# Send Mail Auth Error

**URL:** <https://forum.djangoproject.com/t/send-mail-auth-error/10294>\
**Category:** Using Django\
**Created:** [October 28, 2021, 6:42pm UTC](https://forum.djangoproject.com/t/send-mail-auth-error/10294 "2021-10-28T18:42:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![notrednamc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/notrednamc/32/2812_2.png) [@notrednamc](https://forum.djangoproject.com/u/notrednamc)\
**Post date:** [October 28, 2021, 6:42pm UTC](https://forum.djangoproject.com/t/send-mail-auth-error/10294/1 "2021-10-28T18:42:01Z")

</div>

Hello,

I am wanting my django project to send email when a form is submitted. I have created an account with a license in O365 and believe I have the settings and view code correct but I am getting the following error.

smtplib.SMTPAuthenticationError: (535, b’5.7.139 Authentication unsuccessful, the request did not meet the criteria to be authenticated successfully. Contact your administrator. [[XXXXXXXXX.XXXXXXXX.XXXX.outlook.com](http://XXXXXXXXX.XXXXXXXX.XXXX.outlook.com)]’)

It is not saying the credentials are incorrect so I am not sure what exactly it is looking for.

The relevant parts of settings and views are below

settings.py

```auto
...
AUTHENTICATION_BACKENDS = ('nilmon.auth.EmailBackend',)
# Email Configuration Settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.office365.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'email@domain.com'
EMAIL_HOST_PASSWORD = 'password'
DEFAULT_FROM_EMAIL = 'email@domain.com'

```

views.py

```auto
from django.conf import settings
from django.core.mail import send_mail

def email (request):
...
    subject = 'This is a subject'
    message = 'This is a cool message'
    email_from = settings.EMAIL_HOST_USER
    recipient_list = ['user@domain.com']
    send_mail(subject, message, email_from, recipient_list)
...

```

I have yet to find anything that talks about the criteria the needs to be met to authenticate. Am I on the right track here or should I be doing something else entirely?

---

<div class="post-metadata">

**Author:** ![CodenameTim](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/codenametim/32/31507_2.png) [@CodenameTim](https://forum.djangoproject.com/u/CodenameTim)\
**Post date:** [October 28, 2021, 6:53pm UTC](https://forum.djangoproject.com/t/send-mail-auth-error/10294/2 "2021-10-28T18:53:04Z")

</div>

Have you seen [this Q&A](https://docs.microsoft.com/en-us/answers/questions/512954/535-57139-authentication-unsuccessful.html)? Looks like there are a few idea in there regarding Azure / Active Directory settings.

---

<div class="post-metadata">

**Author:** ![notrednamc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/notrednamc/32/2812_2.png) [@notrednamc](https://forum.djangoproject.com/u/notrednamc)\
**Post date:** [October 28, 2021, 7:13pm UTC](https://forum.djangoproject.com/t/send-mail-auth-error/10294/3 "2021-10-28T19:13:37Z")

</div>

@CodenameTim That is perfect. The answer in the link provided “#4 Exclude the user from a conditional access policy that block legacy authentication” solved my problem.
