我真的很困惑。我能够使用django配置发送电子邮件:
模型:
send_mail_notification(...)
任务:
def send_mail_notification(...):
(...)
send_mail(subject, message, fromname, tolist, fail_silently=False)
这很有效。它发送电子邮件,我收到它。但现在我想让芹菜异步地做到这一点:
模型:
send_mail_notification.apply_async((...), countdown=5)
任务:
@shared_task
def send_mail_notification(...):
(...)
send_mail(subject, message, fromname, tolist, fail_silently=False)
这里奇怪的是,芹菜没有给我任何错误。它说任务成功了,但我从来没有收到过这些电子邮件,只是打印出来了:
[2014-01-18 08:12:12,202: INFO/MainProcess] Received task: mydjangoapp.tasks.send_mail_notification[2dbb5d74-2002-4948-b627-cf3630d1681b] eta:[2014-01-18 08:12:17.184785+00:00]
[2014-01-18 08:12:18,031: WARNING/Worker-1] Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: Match notification
From: fromname
To: myemail@gmail.com
Date: Sat, 18 Jan 2014 08:12:18 -0000
Message-ID: <20140118081218.62652.73949@mycomputer>
(... message body ...)
[2014-01-18 08:12:18,032: WARNING/Worker-1] -------------------------------------------------------------------------------
[2014-01-18 08:12:18,034: INFO/MainProcess] Task mydjangoapp.tasks.send_mail_notification[e9450ef8-8c9a-4179-98c9-b5cd07e6ffc7] succeeded in 0.00458826124668s: None
这里发生了什么?
答案 0 :(得分:2)
从send_mail_notification
调用时返回django.core.email.get_connection
的内容是什么?当您在connection
中指定send_mail
时会发生什么,i。 E:
from django.core.mail import get_connection, send_mail
conn = get_connection(backend='django.core.mail.backends.smtp.EmailBackend')
send_mail(subject, message, fromname, tolist, fail_silently=False, connection=conn)
也许Celery有不同的电子邮件后端?