Django smtp connection with office 365 Outlook

Viewed 412

We are receiving the following error using the Office 365 SMTP server to send mails from the Django application.

    Traceback (most recent call last):
  File "/home/app/views.py", line 598, in send_mail
    django.core.mail.send_mail(
  File "/usr/local/lib/python3.8/site-packages/django/core/mail/__init__.py", line 61, in send_mail
    return mail.send()
  File "/usr/local/lib/python3.8/site-packages/django/core/mail/message.py", line 284, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/usr/local/lib/python3.8/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
    new_conn_created = self.open()
  File "/usr/local/lib/python3.8/site-packages/django/core/mail/backends/smtp.py", line 69, in open
    self.connection.login(self.username, self.password)
  File "/usr/local/lib/python3.8/smtplib.py", line 732, in login
    raise last_exception
  File "/usr/local/lib/python3.8/smtplib.py", line 721, in login
    (code, resp) = self.auth(
  File "/usr/local/lib/python3.8/smtplib.py", line 644, in auth
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.139 Authentication unsuccessful, SmtpClientAuthentication is disabled for the Mailbox. Visit https://aka.ms/smtp_auth_disabled for more information. [PN2PR01CA0172.INDPRD01.PROD.OUTLOOK.COM]')

following setup did in the Django setting.py

EMAIL_HOST=smtp.office365.com
EMAIL_USE_TLS=True
EMAIL_PORT=587 # also tried port 25
EMAIL_USER=test@example.com
EMAIL_PASSWORD=test

And following the steps for setting up the Outlook 365 SMTP relay account (Steps) and also checked the Authenticated SMTP for the admin account. Is I am doing anything wrong or missing anything?

It will be appreciated for any help, Thank you :)

0 Answers
Related