Created
November 19, 2017 16:21
-
-
Save kuzminT/2ed2d0d097dc6437c6d63283ff7d0bc7 to your computer and use it in GitHub Desktop.
Send mail in django with celery
This file contains hidden or 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
| from celery import task | |
| from django.core.mail import send_mail | |
| from .models import Order | |
| @task | |
| def order_created(order_id): | |
| """ | |
| Task to send an e-mail notification when an order is | |
| successfully created. | |
| """ | |
| order = Order.objects.get(id=order_id) | |
| subject = 'Order nr. {}'.format(order.id) | |
| message = 'Dear {},\n\nYou have successfully placed an order.\ | |
| Your order id is {}.'.format(order.first_name, | |
| order.id) | |
| mail_sent = send_mail(subject, | |
| message, | |
| '[email protected]', | |
| [order.email]) | |
| return mail_sent |
This file contains hidden or 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
| from .tasks import order_created | |
| # launch asynchronous task | |
| order_created.delay(order.id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment