ZOHO smtp SMTPAuthenticationError at / (535, 'Authentication Failed') Django 应用程序

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

我正在尝试通过 shell 在 VPS 上使用以下代码建立连接:

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', '*********')

所有凭据都是正确的,因为我在 https://www.zoho.eu/mail/

成功登录了我的帐户

当我尝试登录时:

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

我收到 SMTPAuthenticationError 并且堆栈跟踪显示:

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

我的settings.py是:

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 = '*********'

网络上有很多关于此的话题,但甚至没有人对此有答案。他们的支持现在已经第三天没有回应了...

我正在使用 NGINX,默认配置没有设置为 https://,但我的自定义配置是,网站是 运行 over https://。

编辑:如果我尝试通过端口 587 连接:

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

我得到:

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

这是我在 settings.py 中唯一的设置,足以让它正常工作。

#Email Settings
EMAIL_USE_SSL = True
EMAIL_HOST = 'smtp.zoho.com'
EMAIL_PORT = 465
EMAIL_HOST_USER = 'someone@example.com'
EMAIL_HOST_PASSWORD = 'yourpassword'
DEFAULT_FROM_EMAIL = 'someone@example.com'
SERVER_EMAIL = 'someone@example.com'

您可以使用 Django Docs 中的快速示例对其进行测试。

from django.core.mail import send_mail

send_mail(
    'Subject here',
    'Here is the message.',
    'from@example.com',
    ['to@example.com'],
    fail_silently=False,
)

原来我是在 zoho 的欧洲主机下注册的,所以我通过将 EMAIL_HOST 更改为 'smtp.zoho.eu'

来修复它

我必须添加 ignoreTLS 才能工作

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

看起来你已经解决了这个问题,但我遇到了同样的错误,我发现解决方案是我最近在帐户上启用了 2FA,所以我不得不添加一个应用专用密码。

可以在 Zoho Mail docs.

中找到有关执行此操作的说明