本文整理汇总了Python中flask.ext.mail.Message方法的典型用法代码示例。如果您正苦于以下问题:Python mail.Message方法的具体用法?Python mail.Message怎么用?Python mail.Message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.ext.mail
的用法示例。
在下文中一共展示了mail.Message方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_exception
# 需要导入模块: from flask.ext import mail [as 别名]
# 或者: from flask.ext.mail import Message [as 别名]
def send_exception(subject):
"""Send Python exception tracebacks via email to the ADMINS list.
Use the same HTML styling as Flask tracebacks in debug web servers.
This function must be called while the exception is happening. It picks up the raised exception with sys.exc_info().
Positional arguments:
subject -- subject line of the email (to be prepended by 'Application Error: ').
"""
# Generate and modify html.
tb = tbtools.get_current_traceback() # Get exception information.
with _override_html():
html = tb.render_full().encode('utf-8', 'replace')
html = html.replace('<blockquote>', '<blockquote style="margin: 1em 0 0; padding: 0;">')
subject = 'Application Error: {}'.format(subject)
# Apply throttle.
md5 = hashlib.md5('{}{}'.format(subject, html)).hexdigest()
seconds = int(current_app.config['MAIL_EXCEPTION_THROTTLE'])
lock = redis.lock(EMAIL_THROTTLE.format(md5=md5), timeout=seconds)
have_lock = lock.acquire(blocking=False)
if not have_lock:
LOG.debug('Suppressing email: {}'.format(subject))
return
# Send email.
msg = Message(subject=subject, recipients=current_app.config['ADMINS'], html=html)
mail.send(msg)
示例2: send_email
# 需要导入模块: from flask.ext import mail [as 别名]
# 或者: from flask.ext.mail import Message [as 别名]
def send_email(subject, body=None, html=None, recipients=None, throttle=None):
"""Send an email. Optionally throttle the amount an identical email goes out.
If the throttle argument is set, an md5 checksum derived from the subject, body, html, and recipients is stored in
Redis with a lock timeout. On the first email sent, the email goes out like normal. But when other emails with the
same subject, body, html, and recipients is supposed to go out, and the lock hasn't expired yet, the email will be
dropped and never sent.
Positional arguments:
subject -- the subject line of the email.
Keyword arguments.
body -- the body of the email (no HTML).
html -- the body of the email, can be HTML (overrides body).
recipients -- list or set (not string) of email addresses to send the email to. Defaults to the ADMINS list in the
Flask config.
throttle -- time in seconds or datetime.timedelta object between sending identical emails.
"""
recipients = recipients or current_app.config['ADMINS']
if throttle is not None:
md5 = hashlib.md5('{}{}{}{}'.format(subject, body, html, recipients)).hexdigest()
seconds = throttle.total_seconds() if hasattr(throttle, 'total_seconds') else throttle
lock = redis.lock(EMAIL_THROTTLE.format(md5=md5), timeout=int(seconds))
have_lock = lock.acquire(blocking=False)
if not have_lock:
LOG.debug('Suppressing email: {}'.format(subject))
return
msg = Message(subject=subject, recipients=recipients, body=body, html=html)
mail.send(msg)
示例3: send_email
# 需要导入模块: from flask.ext import mail [as 别名]
# 或者: from flask.ext.mail import Message [as 别名]
def send_email(to, subject, template, **kwargs):
msg = Message(subject, recipients=[to], sender=cfg.get('SMTP', 'sender'))
msg.body = render_template(template + '.txt', **kwargs)
msg.html = render_template(template + '.html', **kwargs)
return mail.send(msg)
示例4: send_verify_email
# 需要导入模块: from flask.ext import mail [as 别名]
# 或者: from flask.ext.mail import Message [as 别名]
def send_verify_email(user, aga_id):
aga_info = get_aga_info(aga_id)
if aga_info is None:
return False
email_address = aga_info['email']
email_subject = "Confirm AGA ID for Online Ratings"
email_body = render_template('verify/verification_email.html',
user=user, aga_id=aga_id, verify_link=get_verify_link(user, aga_id))
email = Message(
recipients=[email_address],
subject=email_subject,
html=email_body,
)
current_app.extensions.get('mail').send(email)
return True
示例5: mail_account
# 需要导入模块: from flask.ext import mail [as 别名]
# 或者: from flask.ext.mail import Message [as 别名]
def mail_account(recipient, subject, body, headers=None):
site_title = current_app.config.get('SITE_TITLE')
if (recipient.email is not None) and len(recipient.email):
msg = Message(subject, recipients=[recipient.email])
msg.body = add_msg_niceties(recipient.display_name, body, site_title)
mail.send(msg)
示例6: send_email
# 需要导入模块: from flask.ext import mail [as 别名]
# 或者: from flask.ext.mail import Message [as 别名]
def send_email(to, subject, template, **kwargs):
msg = Message(subject, sender=MAIL_SENDER, recipients=[to])
msg.body = render_template(template + '.txt', **kwargs)
msg.html = render_template(template + '.html', **kwargs)
thr = Thread(target=send_async_email, args=[app, msg])
thr.start()
return thr
示例7: send_email
# 需要导入模块: from flask.ext import mail [as 别名]
# 或者: from flask.ext.mail import Message [as 别名]
def send_email(to, subject, template):
msg = Message(
subject,
recipients=[to],
html=template,
sender=app.config['MAIL_DEFAULT_SENDER']
)
mail.send(msg)
# Create customized model view class
示例8: send
# 需要导入模块: from flask.ext import mail [as 别名]
# 或者: from flask.ext.mail import Message [as 别名]
def send(recipient, subject, body):
'''
Send a mail to a recipient. The body is usually a rendered HTML template.
The sender's credentials has been configured in the config.py file.
'''
sender = app.config['ADMINS'][0]
message = Message(subject, sender=sender, recipients=[recipient])
message.html = body
# Create a new thread
thr = Thread(target=send_async, args=[app, message])
thr.start()
示例9: send_email
# 需要导入模块: from flask.ext import mail [as 别名]
# 或者: from flask.ext.mail import Message [as 别名]
def send_email(to, subject, template, **kwargs):
app = current_app._get_current_object()
msg = Message(app.config['FLASKY_MAIL_SUBJECT_PREFIX'] + ' ' + subject,
sender=app.config['FLASKY_MAIL_SENDER'], recipients=[to])
msg.body = render_template(template + '.txt', **kwargs)
msg.html = render_template(template + '.html', **kwargs)
send_async_email.delay(msg)
示例10: send_email
# 需要导入模块: from flask.ext import mail [as 别名]
# 或者: from flask.ext.mail import Message [as 别名]
def send_email(to, subject, template):
msg = Message(
subject,
recipients=[to],
html=template,
sender=app.config['MAIL_DEFAULT_SENDER']
)
mail.send(msg)