0

我正在尝试安排异步电子邮件作业。我使用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')

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

4

1 回答 1

0

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

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

于 2016-01-06T21:08:57.803 回答