問題描述
SMTPAuthenticationError:Django 中的身份驗證不成功 [BL1PR13CA0128.namprd13.prod.outlook.com] (SMTPAuthenticationError: Authentication unsuccessful [BL1PR13CA0128.namprd13.prod.outlook.com] in Django)
我正在嘗試從 Django API 發送和發送電子郵件(從我的個人 hotmail 帳戶)。當我通過 Postman 向本地服務器發出請求時,它可以工作,但是當我在 Heroku 上託管我的應用程序時,它會引發以下異常:
我正在閱讀並且 Hotmail 帳戶具有類似 SMTP 權限:
這是我的 Django 配置變量:
參考解法
方法 1:
Make sure your Outlook account settings change Under Pop options to Yes. (I believe you already done it as per your pics)
Check if your outlook account has been blocked by an unusual activity, in that case, you may need to verify your account (via the assigned mobile#) and verify and review your activities (email should looks like below)
To help keep you safe, we've blocked access to your inbox, contacts list, and calendar for that sign‑in. Please review your recent activity and we'll help you secure your account. To regain access, you'll need to confirm that the recent activity was yours. Review recent activity Thanks, The Microsoft account team
In your settings.py change as below
EMAIL_HOST='smtp‑mail.outlook.com'
EMAIL_PORT=587
EMAIL_HOST_USER='your email'
EMAIL_HOST_PASSWORD='password'
EMAIL_USE_TLS=True
server = smtplib.SMTP('smtp.office365.com', 587)
server.starttls()
finally make sure to import smtplib