示例#1
0
def send_email(subject, sender, recipients, text_body, html_body):
    msg = Message(subject, sender=sender, recipients=recipients)
    msg.body = text_body
    msg.html = html_body

    # can handle other logic effectively at the same time
    Thread(target=send_async_email,
           args=(current_app._get_current_object(), msg)).start()
示例#2
0
文件: email.py 项目: boyl/mblog
def send_email(subject, sender, recipients, text_body, html_body,
               attachments=None, sync=False):
    msg = Message(subject, sender=sender, recipients=recipients)
    msg.body = text_body
    msg.html = html_body
    if attachments:
        for attachment in attachments:
            msg.attach(*attachment)
    if sync:
        mail.send(msg)
    else:
        # can handle other logic effectively at the same time
        Thread(target=send_async_email, args=(current_app._get_current_object(), msg)).start()
示例#3
0
文件: email.py 项目: todayzhou/myblog
def send_email(subject, sender, receiver, text_body, html_body, attachments=None, sync=False):
	msg = Message(subject, sender=sender, recipients=receiver)
	msg.body = text_body
	msg.html = html_body
	if attachments:
		for attachment in attachments:
			msg.attach(*attachment)
	# with open('/home/zhou/py_tools/myblog/123', 'rb') as fp:
	# 	msg.attach('123.txt', 'text/plain', fp.read())
	if sync:
		mail.send(msg)
	else:
		threading.Thread(target=send_async_mail, args=(current_app._get_current_object(), msg)).start()
示例#4
0
def initialize_cache():
    from config import Config
    from app.api.events_cache import refresh_cache_thread, refresh_cache
    from app import scheduler, current_app

    # we'll set the run interval just little less than the CACHE TIMEOUT to avoid
    # the refresh be > CACHE_TIMEOUT
    logger.debug("initializing cache")
    refresh_cache(True)
    logger.debug("starting refresh thread")
    scheduler.add_job(refresh_cache_thread,
                      'interval',
                      seconds=Config.CACHE_TIMEOUT - 10,
                      args=[current_app._get_current_object()])
    scheduler.start()
示例#5
0
def send_email(subject, sender, recipients, text_body, html_body):
    """Send an email.

    Args:
        subject: subject
        sender: sender
        recipients: recipients
        text_body: text body
        html_body: html body
    """
    msg = Message(subject, sender=sender, recipients=recipients)
    msg.body = text_body
    msg.html = html_body
    Thread(
        target=send_async_email,
        args=(current_app._get_current_object(), msg),
    ).start()
def send_email(subject, sender, recipients, text_body, html_body):
    msg = Message(subject, sender=sender, recipients=recipients)
    msg.body = text_body
    msg.html = html_body
    Thread(target=send_async_email(current_app._get_current_object(),
                                   msg)).start()