【问题标题】:SMTPSenderRefused error while sending emails from office365 with Django send_mail in Ubuntu 16.04?在 Ubuntu 16.04 中使用 Django send_mail 从 office365 发送电子邮件时出现 SMTPSenderRefused 错误?
【发布时间】:2019-10-17 13:29:49
【问题描述】:

我在 ubuntu 16.04 DigitalOcean 中使用 django send_mail 从 office 365(Godaddy) 发送邮件时遇到一个问题。

这是我的实际配置:

EMAIL_HOST = 'smtp.office365.com'
EMAIL_HOST_USER = "myuser"
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_USE_TLS = True
EMAIL_PORT = 587

发送邮件:

context = {}
subject = 'Verificación de registro con 1 clic'
txt_ = get_template("registration/emails/verify.txt").render(context)
from_email = settings.DEFAULT_FROM_EMAIL
recipient_list = [somemail@somemail.com]
html_ = get_template("registration/emails/verify.html").render(context)
sent_mail = send_mail(
    subject,
    txt_,
    from_email,
    recipient_list,
    html_message=html_,
    fail_silently=False,
)

这是引发的错误:

raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (530, b'5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM []', '=?utf-8?q?myuser?= <myemail@myemail.com>')

【问题讨论】:

    标签: django office365 digital-ocean


    【解决方案1】:

    这是因为几个原因。其中更常见的是如果您的允许安全性较低的应用程序功能被关闭。

    这个https://support.google.com/accounts/answer/6010255 可能对你很有用。

    谷歌说»

    如果您的帐户已关闭“不太安全的应用访问”,您可以turn it back on。我们建议改用more secure apps

    这意味着,您只需直接访问https://myaccount.google.com/lesssecureapps 并打开。

    您也可以访问 https://myaccount.google.com/security 和 Ctrl+F/Command+F » Less secure app access,在其下您可以看到如下图所示的内容。


    我是如何解决这个问题的?

    在我的情况下,我在集成 django-db-mailer 时遇到了错误。

    SMTPSenderRefused: (530, b'5.5.1 Authentication Required. Learn more at\n5.5.1  https://support.google.com/mail/?p=WantAuthError z25sm26247003pfn.7 - gsmtp', 'rishikesh0011115067@gmail.com')
    

    我通过更改 EMAIL_USER -> EMAIL_HOST_USER 设置变量来修复它。

    现在,我得到的下一个错误和你的完全一样。

    SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8  https://support.google.com/mail/?p=BadCredentials m123sm26024478pfb.133 - gsmtp')
    

    我访问了https://myaccount.google.com/lesssecureapps,发现我的帐户的允许不太安全的应用程序功能已关闭。只需切换按钮的状态并运行代码。

    终于成功了。我希望,这可能对你有所帮助。您还可以检查您是否在苦苦挣扎https://devanswers.co/allow-less-secure-apps-access-gmail-account/。已经有太多天了,但我仍然喜欢通过指向你来回答(尽管你已经修复了它)。

    【讨论】:

    • 那是 gmail 的。我的问题是 Outlook 尤其是 office265 电子邮件。
    • 这是给谷歌的。这个问题专门针对office365
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-09
    • 2016-03-02
    • 2021-09-28
    • 1970-01-01
    • 1970-01-01
    • 2020-04-26
    • 1970-01-01
    相关资源
    最近更新 更多