调度异步电子邮件作业失败,错误SMTPAuthenticationError:(535,'5.7.3身份验证失败')

时间:2016-01-06 21:03:01

标签: django django-rq

我正在尝试安排异步电子邮件作业。 我正在使用django-rq作为排队机制。我尝试了很多修复,比如更改密码,确保密码正确等等。我可以通过REPL手动发送SMTP。

更新#1:工人正在正确地选择设置,据我所知。作业正确获取settings.DEFAULT_FROM_EMAIL的正确值,并将正确的电子邮件地址设置为send_mail的arg。

以下代码成功运行(没有django-rq):

send_mail(
    newClaim.linkedOffer.commsPromoHeadline,
    msg_plain,
    settings.DEFAULT_FROM_EMAIL,
    [newRecipient.email],
    html_message=msg_html,
)

虽然以下代码生成SMTP身份验证错误(回溯率较低):

django_rq.enqueue(
   send_mail,
   newClaim.linkedOffer.commsPromoHeadline,
   msg_plain,
   settings.DEFAULT_FROM_EMAIL,
   [newRecipient.email],
   html_message=msg_html,
   )

回溯:

Traceback (most recent call last):
  File "/home/user1/webapps/dev_django_platform/ENV/lib/python2.7/site-packages/rq/worker.py", line 568, in perform_job
    rv = job.perform()
  File "/home/user1/webapps/dev_django_platform/ENV/lib/python2.7/site-packages/rq/job.py", line 495, in perform
    self._result = self.func(*self.args, **self.kwargs)
  File "/home/user1/webapps/dev_django_platform/lib/python2.7/Django-1.7.7-py2.7.egg/django/core/mail/__init__.py", line 62, in send_mail
    return mail.send()
  File "/home/user1/webapps/dev_django_platform/lib/python2.7/Django-1.7.7-py2.7.egg/django/core/mail/message.py", line 286, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/user1/webapps/dev_django_platform/lib/python2.7/Django-1.7.7-py2.7.egg/django/core/mail/backends/smtp.py", line 92, in send_messages
    new_conn_created = self.open()
  File "/home/user1/webapps/dev_django_platform/lib/python2.7/Django-1.7.7-py2.7.egg/django/core/mail/backends/smtp.py", line 59, in open
    self.connection.login(self.username, self.password)
  File "/usr/local/lib/python2.7/smtplib.py", line 622, in login
    raise SMTPAuthenticationError(code, resp)
SMTPAuthenticationError: (535, '5.7.3 Authentication unsuccessful')

为什么会抛出异常,我该如何解决?

1 个答案:

答案 0 :(得分:0)

我的假设是排队任务在单独的工作环境中运行。在Django中,self._children函数知道从哪里查找Auth详细信息。但是在工人内部,它找不到它们,因为它是一个单独的过程。

您需要编写自定义send_mail函数,该函数不依赖于Django来提供它的设置。