Skip to content

Instantly share code, notes, and snippets.

@Quard
Created April 10, 2019 12:54
Show Gist options
  • Save Quard/4c8bd2c5e75631c069759443026d2e09 to your computer and use it in GitHub Desktop.
Save Quard/4c8bd2c5e75631c069759443026d2e09 to your computer and use it in GitHub Desktop.
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