Django Email SMTPAuthenticationError

Hey,

I have a code that sends an email, it worked about 2 weeks ago. Now when I want to send an email I get this error (535, b’5.7.8 Error: authentication failed: authentication failure ').

This is in my settings

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'cmail01.mailhost24.de.'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'noreply@divusx.com'
EMAIL_HOST_PASSWORD = 'passwordhere'

The funny thing is with this email no error appears but the emai is not sent as expected. If the receiver’s email is from gmail the email sents, but in office it doesnt.
If I change the email from settings.py to another emails of mine like info@divusx.com the error from above appears. Something is really weird here.

This is how it should be:

ah and this is my code for the email but it shouldnt be wrong because it worked 2 weeks ago and I didnt change anything.

    email = request.user.email
    send_mail(
        'DivusX - Test Request',
        'Test Text',
        '',
        [email],
        fail_silently=False,
)    

The image indicates the port should be 25, while your EMAIL_PORT setting is set to 587.

yeah I already did that, the problem was that the email there was just delivered to a receiver who has a gmail adress. In outlook the mail doesnt deliver.

Is the call to send_mail raising an error or is the email not being sent? If it’s the latter, I don’t think it’s a django issue.

I think it’s sent it just doesnt gets delivered to my mail because if I try a gmail adress as receiver it works

Try checking your mail’s spam score. It sounds like outlook is marking it as spam and/or.not delivering it.

if I change the port to 25 this error comes on my localhost

STARTTLS extension not supported by server.

@FLYAX it sounds like you might be have an authentication issue (SPF, DKIM). Check those settings with your host and dns provider.

If you’re only doing local development at this point you can use the Console backend to view emails generated by your view.

https://docs.djangoproject.com/en/4.0/topics/email/#console-backend

As you move into production make sure you have the email authentication setup and tested.

I highly recommend using a transactional email service provider. These types of platforms offer email service geared towards notification type email delivery. There is a popular project called Anymail that makes it straightforward to use a transactional email service provider

1 Like