STARTTLS extension not supported by server - Getting this error when trying to send an email through Django and a private email address

孤街醉人 提交于 2019-12-01 03:59:47
Jerzyk

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

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 communication.
  2. 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 whatsoever.
  3. your server is configured improperly and ignores STARTTLS on submission port (587).

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

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

Mukesh M Goswami

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

EMAIL_USE_SSL = True
EMAIL_PORT = 465

hope that helps

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

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

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:

import smtplib
from email.message import EmailMessage

fromaddr = 'account@yourdomain.com'
toaddrs  = "recipient@somedomain.com"
SMTPServer = 'mail.privateemail.com'
port = 465 #587
login = "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'] = fromaddr
msg['To'] = toaddrs

server = 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!