Office 365 SMTP自定义域名发邮件认证失败求助
Django发送Office 365自定义域名邮箱邮件失败:认证错误
我需要使用托管在Office 365中的自定义域名邮箱support@example.com向用户发送邮件,当前Django邮件后端配置如下:
# Email settings EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" EMAIL_HOST = "smtp.office365.com" EMAIL_PORT = 587 EMAIL_USE_TLS = True EMAIL_HOST_USER = "support@example.com" EMAIL_HOST_PASSWORD = "App_password"
执行发送时遇到的具体错误:
Authentication unsuccessful, the request did not meet the criteria to be authenticated successfully. Contact your administrator.
我已验证登录凭据的正确性,同时尝试了587和25端口,问题仍未解决。
对比成功配置:
使用个人Outlook邮箱personal@outlook.com搭配smtp-mail.outlook.com可正常发送邮件,配置如下:
EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" EMAIL_HOST = "smtp-mail.outlook.com" EMAIL_PORT = 587 EMAIL_USE_TLS = True EMAIL_HOST_USER = "personal@outlook.com" EMAIL_HOST_PASSWORD = "App_password"
我确认问题与邮件发送函数无关,以下是函数代码:
def send_email_verification(user): site_url = "https://www.example.com" print("Trying to send email") if user.is_active: return else: print("sending email") confirmation_token = default_token_generator.make_token(user) # unique token activation_link = f"{site_url}/users/api/users/activate/{user.id}/{confirmation_token}" # activation link to be sent in email subject = "Verify your Email address" from_email = settings.EMAIL_HOST_USER to_email = user.email # Load the email template and render it with the activation link html_content = render_to_string('email_verification.html', {'activation_link' : activation_link}) text_content = strip_tags(html_content) # This strips the html, so people will have the text. # Create the email, message and send it. msg = EmailMultiAlternatives(subject, text_content, from_email, [to_email]) msg.attach_alternative(html_content, "text/html") try: msg.send() print(f"Email successfully sent to {user.email}") print(f"confirmation toke = {confirmation_token}") except Exception as e: print(f"an error has occured while sending email : {e}")
恳请有类似经验的人士提供建议、见解或解决方案,感谢支持!
内容的提问来源于stack exchange,提问作者Nawaraj
相关产品推荐
相关产品推荐

