服务器不支持STARTTLS扩展 - 尝试通过Django和私人电子邮件地址发送电子邮件时出现此错误

时间:2021-07-20 21:53:14

I registered a domain and a private email using namecheap.com. I am trying to send an email from this private email. However, I get the error in the title.

我使用namecheap.com注册了域名和私人电子邮件。我正在尝试通过此私人电子邮件发送电子邮件。但是,我在标题中收到错误。

In my settings.py, I have these settings:

在我的settings.py中,我有以下设置:

EMAIL_HOST = 'mail.privateemail.com'EMAIL_HOST_USER = 'contact@mysite.com'EMAIL_HOST_PASSWORD = 'my password'EMAIL_PORT = 587EMAIL_USE_TLS = TrueEMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'DEFAULT_FROM_EMAIL = EMAIL_HOST_USER

And I am trying to send the email through a view:

我正在尝试通过视图发送电子邮件:

send_mail(    'Subject here',    'Here is the message.',    'contact@mysite.com',    ['myname@gmail.com'],    fail_silently=False,)

However, I get this error:

但是,我收到此错误:

SMTPException at /STARTTLS extension not supported by server.

Any idea why? Any help is appreciated.

知道为什么吗?任何帮助表示赞赏。

EDIT

After changing the EMAIL_USE_TLS to False, and also removing it to check both separately, I get this error now:

将EMAIL_USE_TLS更改为False,并将其删除以单独检查后,我现在收到此错误:

SMTP AUTH extension not supported by server.

Any idea why? Thanks!

知道为什么吗?谢谢!

5 个解决方案

#1


9  

your server 'mail.privateemail.com' does not know what is STARTTLS SMTP Commnad is

你的服务器'mail.privateemail.com'不知道什么是STARTTLS SMTP Commnad

this may happen in two cases:1. your server (mail.privateemail.com) do not support secure communication at all and you need to use plain, non-encrypted communication2. you are trying to connect to the port that is already using SSL as the communication, then STARTTLS to upgrade connection to secure make no sense whatsoever3. your server is configured improperly and ignores STARTTLS on submission port (587)

这可能发生在两种情况:1。您的服务器(mail.privateemail.com)根本不支持安全通信,您需要使用普通的非加密通信2。您正在尝试连接到已经使用SSL作为通信的端口,然后STARTTLS将连接升级到安全没有任何意义3。您的服务器配置不正确并忽略提交端口上的STARTTLS(587)

Judging, that you are connecting to port 587 which should provide plain communication - it's either 1 or 3.

判断,您正在连接到应该提供简单通信的端口587 - 它是1或3。

If you want this just work, remove EMAIL_USE_TLS = True or set it to False, otherwise - SMTP server configuration should be fixed.

如果您希望这只是工作,请删除EMAIL_USE_TLS = True或将其设置为False,否则 - 应修复SMTP服务器配置。

#2


1  

Either setup TLS on your mail server or use EMAIL_USE_TLS = False.

在邮件服务器上设置TLS或使用EMAIL_USE_TLS = False。

#3


0  

I am able to resolve the issue with modifying below line of code, by adding port number with server name:

通过添加服务器名称的端口号,我可以通过修改下面的代码行解决问题:

server = smtplib.SMTP('mail.mycompany.com:587')     

#4


0  

Not sure if you have solved the problem yet. I also recently try the 2-month free private email package from NameCheap. Here is my code and it works for me as of Jan 2018:

不确定你是否已经解决了这个问题。我最近还尝试了NameCheap的2个月免费私人电子邮件包。这是我的代码,从2018年1月起它适用于我:

import smtplibfrom email.message import EmailMessagefromaddr = 'account@yourdomain.com'toaddrs  = "recipient@somedomain.com"SMTPServer = 'mail.privateemail.com'port = 465 #587login = "account@yourdomain.com"password = "password"msg = EmailMessage()msgtxt = "http://www.google.com"+"\n\n"+"This is a test."msg.set_content(msgtxt)msg['Subject'] = "Test message"msg['From'] = fromaddrmsg['To'] = toaddrsserver = smtplib.SMTP_SSL(SMTPServer, port) #use smtplib.SMTP() if port is 587#server.starttls()server.login(login, password)server.send_message(msg)server.quit()

Hope this help!

希望这有帮助!

PS. You can also use port 587, but you have to use smtplib.SMTP() instead of smtplib.SMTP_SSL(), and also have to un-comment the server.starttls() line.

PS。您也可以使用端口587,但必须使用smtplib.SMTP()而不是smtplib.SMTP_SSL(),还必须取消注释server.starttls()行。

#5


0  

You may try SSL instead of TLS by making following changes in settings.py

您可以通过在settings.py中进行以下更改来尝试SSL而不是TLS

EMAIL_USE_SSL = TrueEMAIL_PORT = 465

hope that helps

希望有所帮助

#1


9  

your server 'mail.privateemail.com' does not know what is STARTTLS SMTP Commnad is

你的服务器'mail.privateemail.com'不知道什么是STARTTLS SMTP Commnad

this may happen in two cases:1. your server (mail.privateemail.com) do not support secure communication at all and you need to use plain, non-encrypted communication2. you are trying to connect to the port that is already using SSL as the communication, then STARTTLS to upgrade connection to secure make no sense whatsoever3. your server is configured improperly and ignores STARTTLS on submission port (587)

这可能发生在两种情况:1。您的服务器(mail.privateemail.com)根本不支持安全通信,您需要使用普通的非加密通信2。您正在尝试连接到已经使用SSL作为通信的端口,然后STARTTLS将连接升级到安全没有任何意义3。您的服务器配置不正确并忽略提交端口上的STARTTLS(587)

Judging, that you are connecting to port 587 which should provide plain communication - it's either 1 or 3.

判断,您正在连接到应该提供简单通信的端口587 - 它是1或3。

If you want this just work, remove EMAIL_USE_TLS = True or set it to False, otherwise - SMTP server configuration should be fixed.

如果您希望这只是工作,请删除EMAIL_USE_TLS = True或将其设置为False,否则 - 应修复SMTP服务器配置。

#2


1  

Either setup TLS on your mail server or use EMAIL_USE_TLS = False.

在邮件服务器上设置TLS或使用EMAIL_USE_TLS = False。

#3


0  

I am able to resolve the issue with modifying below line of code, by adding port number with server name:

通过添加服务器名称的端口号,我可以通过修改下面的代码行解决问题:

server = smtplib.SMTP('mail.mycompany.com:587')     

#4


0  

Not sure if you have solved the problem yet. I also recently try the 2-month free private email package from NameCheap. Here is my code and it works for me as of Jan 2018:

不确定你是否已经解决了这个问题。我最近还尝试了NameCheap的2个月免费私人电子邮件包。这是我的代码,从2018年1月起它适用于我:

import smtplibfrom email.message import EmailMessagefromaddr = 'account@yourdomain.com'toaddrs  = "recipient@somedomain.com"SMTPServer = 'mail.privateemail.com'port = 465 #587login = "account@yourdomain.com"password = "password"msg = EmailMessage()msgtxt = "http://www.google.com"+"\n\n"+"This is a test."msg.set_content(msgtxt)msg['Subject'] = "Test message"msg['From'] = fromaddrmsg['To'] = toaddrsserver = smtplib.SMTP_SSL(SMTPServer, port) #use smtplib.SMTP() if port is 587#server.starttls()server.login(login, password)server.send_message(msg)server.quit()

Hope this help!

希望这有帮助!

PS. You can also use port 587, but you have to use smtplib.SMTP() instead of smtplib.SMTP_SSL(), and also have to un-comment the server.starttls() line.

PS。您也可以使用端口587,但必须使用smtplib.SMTP()而不是smtplib.SMTP_SSL(),还必须取消注释server.starttls()行。

#5


0  

You may try SSL instead of TLS by making following changes in settings.py

您可以通过在settings.py中进行以下更改来尝试SSL而不是TLS

EMAIL_USE_SSL = TrueEMAIL_PORT = 465

hope that helps

希望有所帮助