Send Mail Auth Error


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. []’)

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

AUTHENTICATION_BACKENDS = ('nilmon.auth.EmailBackend',)
# Email Configuration Settings
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

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 = ['']
    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?

Have you seen this Q&A? Looks like there are a few idea in there regarding Azure / Active Directory settings.

@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.