SMTP AUTH extension not supported by server
There is no need to call smtp.connect() and smtp.ehlo() , because they are called automatically by SMTP() and smtp.starttls() . The issue is solved simply setting port to 587 instead of 28 .
For client use, if you don’t have any special requirements for your security policy, it is highly recommended that you use the create_default_context() function to create your SSL context. It will load the system’s trusted CA certificates, enable certificate validation and hostname checking, and try to choose reasonably secure protocol and cipher settings.
In general, you will want to use the email package’s features to construct an email message, which you can then send via send_message() .
import smtplib, ssl from email.message import EmailMessage msg = EmailMessage() msg.set_content("The body of the email is here") msg["Subject"] = "An Email Alert" msg["From"] /cdn-cgi/l/email-protection" data-cfemail="48252d082d30292538242d662b2725">[email protected]" msg["To"] /cdn-cgi/l/email-protection" data-cfemail="047d6b7144617c65697468612a676b69">[email protected]" context=ssl.create_default_context() with smtplib.SMTP("smtp.example.com", port=587) as smtp: smtp.starttls(context=context) smtp.login(msg["From"], "[email protected]") smtp.send_message(msg)
Solution 3
It is probably just the server I was using, but was getting the same error as the OP even after implementing the accepted solution. Turned out the server did not want a login, so after deleting the line server.login(fromaddr, «password») , the error went away and it worked.
Solution 4
you need to ‘starttls’ before login.
Solution 5
import smtplib s = smtplib.SMTP('smtplib.gmail.com',587) s.ehlo() s.starttls() s.login('frmaddr','password') try: s.sendmail('fromaddr','toaddr','message') except: print (failed)