如果有人遇到这个问题,我将衷心感谢您的帮助。
我在发送带有hotmail的本地电子邮件时遇到此错误:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/huey/consumer.py", line 169, in process_task
task_value = self.huey.execute(task)
File "/usr/local/lib/python3.6/site-packages/huey/api.py", line 357, in execute
result = task.execute()
File "/usr/local/lib/python3.6/site-packages/huey/api.py", line 842, in execute
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/huey/contrib/djhuey/__init__.py", line 108, in inner
return fn(*args, **kwargs)
File "/code/app/tasks.py", line 89, in send_email
email_message.send()
File "/usr/local/lib/python3.6/site-packages/django/core/mail/message.py", line 348, in send
return self.get_connection(fail_silently).send_messages([self])
File "/usr/local/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 111, in send_messages
sent = self._send(message)
File "/usr/local/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 127, in _send
self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='rn'))
File "/usr/local/lib/python3.6/smtplib.py", line 888, in sendmail
raise SMTPDataError(code, resp)
smtplib.SMTPDataError: (432, b'4.3.2 STOREDRV.ClientSubmit; sender thread limit exceeded [Hostname=DM5PR19MB1050.namprd19.prod.outlook.com]')
ERROR process_task Unhandled exception in worker thread
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/huey/consumer.py", line 169, in process_task
task_value = self.huey.execute(task)
File "/usr/local/lib/python3.6/site-packages/huey/api.py", line 357, in execute
result = task.execute()
File "/usr/local/lib/python3.6/site-packages/huey/api.py", line 842, in execute
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/site-packages/huey/contrib/djhuey/__init__.py", line 108, in inner
return fn(*args, **kwargs)
File "/code/app/tasks.py", line 89, in send_email
email_message.send()
File "/usr/local/lib/python3.6/site-packages/django/core/mail/message.py", line 348, in send
return self.get_connection(fail_silently).send_messages([self])
File "/usr/local/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 111, in send_messages
sent = self._send(message)
File "/usr/local/lib/python3.6/site-packages/django/core/mail/backends/smtp.py", line 127, in _send
self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='rn'))
File "/usr/local/lib/python3.6/smtplib.py", line 888, in sendmail
raise SMTPDataError(code, resp)
smtplib.SMTPDataError: (554, b'5.2.0 STOREDRV.Submission.Exception:SendAsDeniedException.MapiExceptionSendAsDenied; Failed to process message due to a permanent exception with message Cannot submit message. 16.55847:050B0000, 17.43559:0000000094000000000000000000000000000000, 20.52176:140F248214004010F1030000, 20.50032:140F248285174010F1030000, 0.35180:0A00B681, 255.23226:F1030000, 255.27962:0A000000, 255.27962:0E000000, 255.31418:0A00F784, 16.55847:EC000000, 17.43559:0000000068010000000000000000000000000000, 20.52176:140F2482140000100A00F736, 20.50032:140F24828517001181170000, 0.35180:00000000, 255.23226:00000000, 255.27962:0A000000, 255.27962:32000000, 255.17082:DC040000, 0.27745:140F2482, 4.21921:DC040000, 255.27962:FA000000, 255.1494:A4010000, 0.37692:05000780, 0.37948:00000600, 5.33852:00000000534D545000000000, 4.56248:DC040000, 7.40748:010000000000010B32303A44, 7.57132:00000000000000003A346638, 1.63016:32000000, 4.39640:DC040000, 8.45434:0000060075AF4541000000000000000032000000, 5.10786:0000000031352E32302E303534382E3032303A444D35505231394D42313035303A34663832663161652D373465382D343830632D623637302D34326236313339313335383200401005000780, 255.1750:0A00FC83, 255.31418:41010000, 0.22753:0A001E85, 255.21817:DC040000, 4.60547:DC040000, 0.21966:4B010000, 4.30158:DC040000 [Hostname=DM5PR19MB1050.namprd19.prod.outlook.com]')
这是我对 settings.py 的配置 我尝试将端口更改为587,尝试使用gmail帐户但不起作用
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp-mail.outlook.com'
EMAIL_HOST_USER = 'myemail@hotmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 25
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
它可能在 settings.py 或您的视图中缺少"电子邮件发件人"变量。 试试这个:
EMAIL_USE_TLS = True
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.live.com'
EMAIL_HOST_USER = 'youremail@hotmail.com'
DEFAULT_FROM_EMAIL = 'youremail@hotmail.com'
EMAIL_FROM = 'youremail@hotmail.com'
EMAIL_HOST_PASSWORD = 'yourpassword'
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL
用于库存 Django 视图,但如果您有自己的自定义视图,那么您也可以导入这些变量:
from django.conf import settings
send_mail(
mail_subject,
message,
settings.EMAIL_FROM,
[to_email],
fail_silently=False,
)
- 这可以通过在settings.py中添加以下行来轻松解决:
EMAIL_HOST_USER = "support@urmail.com"
DEFAULT_FROM_EMAIL = "support@urmail.com"
确保EMAIL_HOST_USER
和DEFAULT_FROM_EMAIL
是相同的电子邮件 ID。
send_mail
也可以完美运行,但没有在该选项中添加附件的功能。