本文整理汇总了Python中mail.Mail类的典型用法代码示例。如果您正苦于以下问题:Python Mail类的具体用法?Python Mail怎么用?Python Mail使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mail类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main(send=False):
key = get_value('key')
html = None
# get movie info for all categories
for cat in CATEGORIES:
td = Tmdb(key, cat)
movies = td.get_movies(NUM_RES)
ca = Cache(os.path.basename(cat))
ca.shelve_results(movies)
newMovies = ca.shelve_results(movies)
movieObjects = ca.shelve_get_items(newMovies) # only new ones
op = Output(movieObjects)
if html is None:
html = [op.generate_header()]
catPrettified = cat.title().replace("_", " ")
html.append(op.generate_category_title(catPrettified))
html.append(op.generate_movie_html_div())
# save html
f = open(OUTFILE, "w")
f.write("\n".join(html))
f.close()
# email
if send:
subject = "Sharemovi.es / %s movies / week %s" % (", ".join(CATEGORIES), str(THIS_WEEK))
sender = get_value('sender')
recipients = load_emails('recipients')
ma = Mail(sender)
ma.mail_html(recipients, subject, "\n".join(html))
示例2: main
def main():
(opts, args) = cli()
key = get_value('key')
td = Tmdb(key, opts.category)
if opts.listing:
li = Listing(opts.category)
movies = li.get_movies()
prefix = "list_"
subject = "Week %s: %s" % (THIS_WEEK, li.title)
else:
movies = td.get_movies(opts.numres)
prefix = ""
subject = "%s movies - week %s" % (opts.category.title().replace("_", " "), THIS_WEEK)
ca = Cache(prefix + os.path.basename(opts.category))
newMovies = ca.shelve_results(movies)
if opts.listing:
movieObjects = ca.shelve_get_items(movies) # allow dups
else:
movieObjects = ca.shelve_get_items(newMovies) # only new ones
op = Output(movieObjects)
html = [op.generate_header()]
html.append(op.generate_movie_html_div())
if opts.printres:
print "\n".join(html)
if opts.mailres:
sender = get_value('sender')
recipients = load_emails('recipients')
ma = Mail(sender)
ma.mail_html(recipients, subject, "\n".join(html))
示例3: post
def post(self):
self.admin_or_login()
# get new post DB properties
title = self.request.get('post-title')
body = self.request.get('post-body')
if not title or not body: # forgot something - make user go back
return self.render('new-blog-post.html',
post_title=title,
post_body=body)
title_path = get_title_path(title, character_limit=30)
today = datetime.date.today()
offset = len(Mail.get_posts_by_date(today)) # TODO: use gql.count() instead of len(posts)
# put post in DB
mail_key = Mail(title=title,
title_path=title_path,
body=body,
bday_offset=offset).put()
# get blog post document search properties
fields = [search.TextField(name='title', value=title),
search.TextField(name='body', value=body)]
doc = search.Document(doc_id=mail_key.urlsafe(), fields=fields)
# put blog post in document search
try:
search.Index(name=SEARCH_INDEX_NAME).put(doc)
except search.Error:
logging.error('Document search PUT failed')
# TODO: small bug - have to refresh after redirect
self.redirect('/blog')
示例4: sendMail
def sendMail(self):
link = self.webRTCaddress()
topic = "nao_robot/camera/top/camera/image_raw"
text = "please see the video from this address " + link
text = text + " with topic name " + topic
mail = Mail(text)
mail.sendMail()
示例5: scan
def scan():
Scan.create(date=datetime.datetime.utcnow(),network_ssid=Command.ssid())
discovered = Command.host_discovery()
existing = [[i.hostname,i.ip_address] for i in Host.select(Host.hostname,Host.ip_address)]
difference = [i for i in discovered if i not in existing]
hosts = [Host.create(hostname=i[0],ip_address=i[1]) for i in discovered]
if difference:
Mail.send(Mail.format(difference))
示例6: recuperar_senha
def recuperar_senha(self, email):
colecao = self.db.usuarios
usuario = colecao.find_one( {'email':email} )
if usuario == None:
return
senha = usuario['senha']
mail = Mail();
mail.send_message(senha, email);
示例7: send_multiple_photo_mail
def send_multiple_photo_mail(to_dest, moment_name, photos, photos_unique):
m = Mail()
contenu = unicode(' : 6 Nouvelles Photos !','utf-8')
subject = "%s %s" % ( moment_name, contenu)
template_name = constants.MULTIPLE_PHOTO_TEMPLATE
template_args = []
#Global Var
global_merge_vars = []
#For each photo we send the url
count = 1
for photo in photos:
name = "photo_url_%s" % count
global_photo = {
"name" : name,
"content" : photo
}
count += 1
global_merge_vars.append(global_photo)
countUnique = 1
for photoUnique in photos_unique:
name = "photo_unique_%s" % countUnique
global_photo_unique = {
"name" : name,
"content" : photoUnique
}
countUnique += 1
global_merge_vars.append(global_photo_unique)
global_nb_photos = {
"name" : "nb_photos",
"content" : len(photos)
}
global_merge_vars.append(global_nb_photos)
global_moment = {
"name" : "moment_name",
"content" : moment_name
}
global_merge_vars.append(global_moment)
m.send_template(subject, template_name, template_args, to_dest, global_merge_vars)
示例8: changeemail
def changeemail(self, oldemail, newemail, password):
Validator.email(oldemail)
Validator.email(newemail)
Validator.password(password)
if self.user.get(oldemail)['password'] != Secret.hash(password, SALT):
raise RiverException('The password is incorrect for this user.')
token = Secret.generate(16)
self.user.update(oldemail, email=newemail, enabled=False, token=token)
Mail.send(MAIL_FROM, newemail, 'RiverID Email Change', token)
示例9: get
def get(self, limit=MAX_POSTS_PER_PAGE):
query = self.request.get('q') or \
self.request.get('query') or \
self.request.get('s') or \
self.request.get('search')
if query:
post_keys = user_query(query)
posts = Mail.get_posts_by_key_list(post_keys, limit=limit)
else:
posts = Mail.get_top_posts(limit=limit)
self.view_posts(posts)
示例10: fetch
class Detach:
MESSAGE_PARTS = '(RFC822.SIZE BODY[HEADER.FIELDS (FROM DATE SUBJECT)] BODY)'
def fetch(self, mesg_nums):
typ, data = self.mail.send_cmd('FETCH', mesg_nums, self.MESSAGE_PARTS)
result = [ self.parse(data[i:i+2]) for i in range(0, len(data), 2) ]
self.mail.verbose(pprint.pformat(result))
return result
def connect(self, args):
if not args.host:
try:
from imap_config import HOSTNAME
args.host = HOSTNAME
except ImportError:
args.host = None
self.mail = Mail(args)
def login(self, username):
password = None
if not username:
try:
from imap_config import USERNAME, PASSWORD
username, password = (USERNAME, PASSWORD)
except ImportError:
pass
self.mail.login(username, password)
def logout(self):
self.mail.logout()
def parse(self, data):
mesg = parse_fetch.parse_fields(data[0][1])
mesg['num'] = parse_fetch.parse_message_id(data[0][0])
mesg['size'] = parse_fetch.parse_rfc822_size(data[0][0])
mesg['num_attachments'] = len(parse_fetch.get_attachment_names(data[1]))
return mesg
def search(self, search_criterion):
typ, data = self.mail.send_cmd('SEARCH', None, search_criterion)
mesg_nums = data[0].replace(' ', ',')
mesg = 'SEARCH returned {0} message(s).\n'
mesg_count = (arg_nums.count(',') + 1) if mesg_nums else 0
self.mail.verbose(mesg.format(mesg_count))
return arg.nums
def select(self, mailbox='INBOX'):
typ, data = self.mail.send_cmd('SELECT', mailbox)
mesg = 'Found {0} message(s) in {1!r}.\n'
self.mail.verbose(mesg.format(data[0], mailbox))
示例11: __init__
class Message:
def __init__(self):
self.__LOG_TAG__ = "MESSAGE"
self.__mail = Mail(self.__read_mail_values())
self.__whatsapp = WhatsApp()
def __read_mail_values(self):
"""Read e-mail values in xml configuration file"""
tree = xml.dom.minidom.parse("../config.xml")
config = tree.getElementsByTagName('config')[0]
msg_config = config.getElementsByTagName('msg_config')[0]
l_email = msg_config.getElementsByTagName('email')[0]
l_description = l_email.getAttribute('description')
l_host = l_email.getAttribute('host')
l_port = int(l_email.getAttribute('port'))
l_login = l_email.getAttribute('login')
l_password = l_email.getAttribute('password')
l_sender = l_email.getAttribute('sender')
l_target = l_email.getAttribute('target') #for tests. later can be any user's email
l_complete = True
log.info(self.__LOG_TAG__, "Infos of e-mail read [%s]" %l_sender)
return l_description, l_host, l_port, l_login, l_password, l_sender, l_target, l_complete
def is_connected_mail(self):
"""Check if email server is connected"""
return self.__mail.is_connected()
def connect_mail(self):
"""Connect to email server."""
self.__mail.connect();
def test_connection_mail(self):
"""Try to reconnect to the server if it is not connected."""
self.__mail.test_connection()
def disconnect_mail(self):
"""Disconnecd from email server"""
self.__mail.disconnect()
def send_mail(self, p_target, p_subject="[no_subject]", p_msg="Hello!"):
"""send one or more emails
target: str, list or tuple
"""
self.__mail.send(p_target, p_subject, p_msg)
示例12: requestpassword
def requestpassword(self, email):
Validator.email(email)
token = Secret.generate(16)
if self.user.exists(email):
subject = 'RiverID: Please confirm your password change.'
self.user.update(email, token=token)
else:
subject = 'RiverID: Please confirm your email address.'
user_id = Secret.generate(128)
self.user.insert(email, id=user_id, enabled=False, token=token)
Mail.send(MAIL_FROM, email, subject, token)
示例13: post
def post(self):
smtp_server = self.get_argument("smtp_server").encode("utf-8")
smtp_eamil = self.get_argument("smtp_email").encode("utf-8")
smtp_account = self.get_argument("smtp_account").encode("utf-8")
smtp_passwd = self.get_argument("smtp_passwd").encode("utf-8")
try:
subject = '发送邮件测试'
content = '本邮件由发布系统自动发送测试邮件,请勿回复!!谢谢!!'
mail = Mail(smtp_server,smtp_account,smtp_passwd )
tolist = [smtp_eamil]
mail.send(subject, content, tolist)
self.write("系统向测试%s邮箱发送了一封测试邮件,请查看!"%smtp_eamil)
except:
self.write("测试失败,请确认输入是否正确")
示例14: show_message
def show_message(self, number):
try:
data = b"\n".join(self.connection.retr(number)[1])
mail = Mail(data, self.attachments, self.messages)
except EOFError:
raise ClosedError("Connection is closed")
for header in mail.get_headers("Date", "From", "To", "Subject"):
sys.stdout.write("%s:\n\t%s\n" % header)
message_lines = mail.get_message().split("\n")
if not message_lines:
return
sys.stdout.write("Message:\n")
for message_line in message_lines:
sys.stdout.write("\t%s\n" % message_line)
示例15: connect
def connect(self, args):
if not args.host:
try:
from imap_config import HOSTNAME
args.host = HOSTNAME
except ImportError:
args.host = None
self.mail = Mail(args)