Henry Lynx
Henry Lynx

Reputation: 1129

ZOHO smtp SMTPAuthenticationError at / (535, 'Authentication Failed') Django app

I am trying to establish a connection via shell on the VPS with this code:

import smtplib
from email.mime.text import MIMEText


sender = 'my zoho email'
recipient = 'my gmail account email'


msg = MIMEText("Message text")
msg['Subject'] = "Sent from python"
msg['From'] = sender
msg['To'] = recipient


server = smtplib.SMTP_SSL('smtp.zoho.com', 465)

# Perform operations via server
server.login('my zoho account email', '*********')

All the credentials are correct, since I am login in successfully to my account at https://www.zoho.eu/mail/

When i try to login with:

server.login('my zoho account email', '*********')

I get SMTPAuthenticationError and the stack trace shows:

 self.connection.login(force_str(self.username), force_str(self.password)) 
 ...
 raise SMTPAuthenticationError(code, resp)

my settings.py is:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'     
EMAIL_USE_TSL = True
EMAIL_PORT = 465
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_HOST_USER = '**********'
EMAIL_HOST_PASSWORD = '*********'

There are numerous threads about this on the web but, not even one has an answer about it. Their support doesn't answer for third day now...

I am using NGINX and the default configuration is not set for https:// but my custom configuration is and the website is running over https://.

Edit: If I try to connect over port 587 with:

server = smtplib.SMTP_SSL('smtp.zoho.com', 587)

I get:

SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:590)

Upvotes: 2

Views: 3602

Answers (4)

ntk4
ntk4

Reputation: 1307

Looks like you've already got this solved, but I was having this same error and figured out that the solution was that I had recently enabled 2FA on the account, so I had to add an App Specific Password.

Instructions for doing this can be found in the Zoho Mail docs.

Upvotes: 0

Toshiuk Hirahata
Toshiuk Hirahata

Reputation: 7

I had to add ignoreTLS to work

const transport = nodemailer.createTransport({
    host: "smtp.zoho.eu",
    port: 465,
    secure: true,
    auth: {
        user: config.ZOHO_USER,
        pass: config.ZOHO_PASS
    },
    ignoreTLS: true // <----
});

Upvotes: 0

Henry Lynx
Henry Lynx

Reputation: 1129

Turns out I was registered under the European host of zoho so I fixed it by changing the EMAIL_HOST to 'smtp.zoho.eu'

Upvotes: 14

Jose Cherian
Jose Cherian

Reputation: 7737

This is the only setting I have in settings.py and it is enough to get it working.

#Email Settings
EMAIL_USE_SSL = True
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_PORT = 465
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'yourpassword'
DEFAULT_FROM_EMAIL = '[email protected]'
SERVER_EMAIL = '[email protected]'

You can test it using the quick example from Django Docs.

from django.core.mail import send_mail

send_mail(
    'Subject here',
    'Here is the message.',
    '[email protected]',
    ['[email protected]'],
    fail_silently=False,
)

enter image description here

Upvotes: 2

Related Questions