Django使用SMTP通过公司的Outlook服务器发送电子邮件

kb5ga3dv  于 2023-05-01  发布在  Go
关注(0)|答案(1)|浏览(177)

我正在尝试通过公司的smtp服务器发送电子邮件。以下是我的设置:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'blah'
EMAIL_HOST_USER = 'blah'
EMAIL_HOST_PASSWORD = 'blah'
EMAIL_PORT = 587
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
SERVER_EMAIL = EMAIL_HOST_USER

下面是我得到的错误消息:

[22/Jun/2016 17:31:20] ERROR [uer_application.views:68] Traceback (most recent call last):
Traceback (most recent call last):
  File "/Users/cheng/Dev/diandi/uer_application/views.py", line 65, in send_email
  File "/Users/cheng/Dev/diandi/uer_application/views.py", line 65, in send_email
    email.send(fail_silently=False)
    email.send(fail_silently=False)
  File "/Users/cheng/.virtualenvs/diandi/lib/python2.7/site-packages/django/core/mail/message.py", line 292, in send
  File "/Users/cheng/.virtualenvs/diandi/lib/python2.7/site-packages/django/core/mail/message.py", line 292, in send
    return self.get_connection(fail_silently).send_messages([self])
    return self.get_connection(fail_silently).send_messages([self])
  File "/Users/cheng/.virtualenvs/diandi/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
  File "/Users/cheng/.virtualenvs/diandi/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 100, in send_messages
    new_conn_created = self.open()
    new_conn_created = self.open()
  File "/Users/cheng/.virtualenvs/diandi/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 67, in open
  File "/Users/cheng/.virtualenvs/diandi/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 67, in open
    self.connection.login(self.username, self.password)
    self.connection.login(self.username, self.password)
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 622, in login
  File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 622, in login
    raise SMTPAuthenticationError(code, resp)
    raise SMTPAuthenticationError(code, resp)
SMTPAuthenticationError: (535, '5.7.3 Authentication unsuccessful')

我通过门户网站测试了用户名和密码,它的工作。所以我很好奇我的设置文件中是否有任何错误(或者可能我错过了什么?)

更新

谢谢你,我犯了一个愚蠢的错误:
用户名不应包含@blah.com部分。..

6vl6ewon

6vl6ewon1#

用这个

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 25
EMAIL_HOST_USER = 'Your gmail address'
EMAIL_HOST_PASSWORD = 'Your password'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
SERVER_EMAIL = EMAIL_HOST_USER

请确保您提供了一个有效的Gmail ID和密码

相关问题