【问题标题】:How to send emails using RabbitMq and Django如何使用 RabbitMq 和 Django 发送电子邮件
【发布时间】:2021-06-02 11:26:00
【问题描述】:

我同时是 RabbitMQ 的新手,如果可能的话,有人还会将我链接到一个很好的任务教程吗?

【问题讨论】:

    标签: django rabbitmq celery


    【解决方案1】:

    这是一个很好的设置教程:

    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

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

    参考: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
    

    【讨论】:

    • 我已按照文档进行操作,但我仍然无法正常工作,有什么可以帮助我的吗?我花了几个小时在这上面没有任何进展
    • 您能否更具体地说明您在哪一点上遇到了麻烦..
    • Nvm 终于搞定了
    猜你喜欢
    • 2020-01-24
    • 2013-03-07
    • 1970-01-01
    • 1970-01-01
    • 2011-05-25
    • 2022-10-18
    • 2011-10-18
    • 2016-06-10
    • 2013-12-16
    相关资源
    最近更新 更多