如何使用 RabbitMq 和 Django 发送电子邮件

How to send emails using RabbitMq and Django

同时我是 RabbitMQ 的新手,如果可能的话,有人会 link 为我的任务提供一个很好的教程吗?

这里有一个很好的设置教程:

https://simpleisbetterthancomplex.com/tutorial/2017/08/20/how-to-use-celery-with-django.html#installing-rabbitmq-on-ubuntu-1604

关于 RabbitMQ 安装的更多信息:https://www.rabbitmq.com/install-debian.html

设置完成后,您可以发送创建芹菜任务的电子邮件。

参考:https://medium.com/@juwelariful1/send-mail-in-django-with-gmail-and-smtp-include-celery-and-gmail-configuration-4b07ae4f8542

有关 django 文档的更多信息: https://docs.djangoproject.com/en/3.2/topics/email/

tasks.py

from celery import shared_task
from django.core.mail.message import EmailMultiAlternatives

@shared_task
def send_email_to(subject, body, from_email, to_email):
    try:
        email = EmailMultiAlternatives(subject, body, from_email, [to_email])
        email.content_subtype = 'html'
        email.send()
    except:
        pass