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

前端 未结 5 1044
南笙
南笙 2021-01-12 04:34

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.

In my set

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-12 05:26

    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.

提交回复
热议问题