SMTPAuthenticationError: Authentication unsuccessful [BL1PR13CA0128.namprd13.prod.outlook.com] in Django

848 Views Asked by At

i'm trying to send and email (from my personal hotmail account) from a Django API. When i make a request through Postman to the local server it works but when i host my app on Heroku it raise the following exception:

enter image description here

I've reading and Hotmail accounts have something like SMTP permissions:

enter image description here

Here is my Django config vars:

CORS_ALLOWED_ORIGINS = ['https://gianlop3z-dev.web.app']

EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST = 'smtp.office365.com'
EMAIL_HOST_PASSWORD = environ.get('EMAIL_HOST_PASSWORD')
EMAIL_HOST_USER = environ.get('EMAIL_HOST_USER')

django_heroku.settings(locals())

The environment variables are in Heroku.

1

There are 1 best solutions below

0
Ranga On

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