SHARE
TWEET

Untitled

a guest Jun 20th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from threading import Thread
  2.  
  3. def send_async_email(msg):
  4.     sleep(10)
  5.     print('Sending message')
  6.     mail.send(msg)
  7.  
  8. def send_email(subject, sender, recipients, text_body, html_body):
  9.     msg = Message(subject, sender = sender, recipients = recipients)
  10.     msg.body = text_body
  11.     msg.html = html_body
  12.     thr = Thread(target = send_async_email, args = [msg])
  13.     thr.start()
  14.      
  15. async def send_async_mail(app, msg):
  16.     with app.app_context():
  17.         mail.send(msg)
  18.  
  19.  
  20. def send_mail(subject, sender, recipients, text_body, html_body):
  21.     msg = Message(subject, sender=sender, recipients=recipients)
  22.     msg.body = text_body
  23.     msg.html = html_body
  24.     mail.send(msg)
  25.     send_async_mail(app, msg)
  26.      
  27. RuntimeWarning: coroutine 'send_async_mail' was never awaited send_async_mail(app, msg)
  28. RuntimeWarning: Enable tracemalloc to get the object allocation traceback
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top