From c1ff98cdf3bac6d0e91aa711327a8023745fdaa6 Mon Sep 17 00:00:00 2001 From: Matt Wright Date: Thu, 19 Dec 2013 13:35:03 -0500 Subject: [PATCH] Document . Addresses #194 --- docs/customizing.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/customizing.rst b/docs/customizing.rst index 33257c6..ae5248c 100644 --- a/docs/customizing.rst +++ b/docs/customizing.rst @@ -140,3 +140,23 @@ templates you can specify an email context processor with the @security.mail_context_processor def security_mail_processor(): return dict(hello="world") + + +Emails with Celery +------------------ + +Sometimes it makes sense to send emails via a task queue, such as +`Celery`_. To delay the sending of emails you can +use the ``@security.send_mail_task`` decorator like so:: + + # Setup the task + @celery.task + def send_security_email(msg): + # Use the Flask-Mail extension instance to send the incoming ``msg`` parameter + # which is an instance of `flask_mail.Message` + mail.send(msg) + + @security.send_mail_task + def delay_security_email(msg): + send_security_email.delay(msg) +