Created
April 10, 2019 12:54
-
-
Save Quard/4c8bd2c5e75631c069759443026d2e09 to your computer and use it in GitHub Desktop.
The Python Celery Cookbook: Small Tool, Big Possibilities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@celery_app.task(bind=True, default_retry_delay=10 * 60) | |
def send_mail_task(self, recipients, subject, template, context): | |
message = render_template(f'{template}.txt', context) | |
html_message = render_template(f'{template}.html', context) | |
try: | |
send_mail( | |
subject=subject, | |
message=message, | |
from_email=settings.DEFAULT_FROM_EMAIL, | |
recipient_list=recipients, | |
fail_silently=False, | |
html_message=html_message | |
) | |
except smtplib.SMTPException as ex: | |
self.retry(exc=ex) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment