Skip to content

Instantly share code, notes, and snippets.

@athoune
Created February 12, 2024 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save athoune/9f68c6fa914b42480f573b2823ad922e to your computer and use it in GitHub Desktop.
Save athoune/9f68c6fa914b42480f573b2823ad922e to your computer and use it in GitHub Desktop.
Test your SMTP settings
import smtplib
import base64
user = 'bob'
password = 'password'
# The server handle TLS connection, not the boring STARTTLS upgrade
server = smtplib.SMTP_SSL(host='smtp.example.com', timeout=5)
server.ehlo() # the server say its name and handled commands, you should see "AUTH PLAIN"
# The RFC for SMTP doesn't say wich text encoding must be used, smtplib use low ASCII, lets forge the command
server.docmd("AUTH PLAIN", b64encode(f"\0{user}\0{password}".encode("utf8")).decode("ascii"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment