How to send emails in background in python webapplication with flask framework? -


i need sent emails large number of recipients attachments web application after completing event. want run in background in order not affect main application processes. how implement this?

miguel grinberg gives complete example of in flask mega tutorial.

basically can push mail sending thread.

from threading import thread app import app  def send_async_email(app, msg):     app.app_context():         mail.send(msg)  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     thr = thread(target=send_async_email, args=[app, msg])     thr.start() 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -