Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The Python Celery Cookbook: Small Tool, Big Possibilities
@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