Skip to content

Instantly share code, notes, and snippets.

@kmkmjhyiiiu
Forked from miohtama/smtp-test.py
Last active June 13, 2022 17:28
Show Gist options
  • Save kmkmjhyiiiu/ec464d89e26c0376aed82892b5790d64 to your computer and use it in GitHub Desktop.
Save kmkmjhyiiiu/ec464d89e26c0376aed82892b5790d64 to your computer and use it in GitHub Desktop.
Testing SMTP server from command line using python
# skipped your comments for readability
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
me = ""
my_password = r""
you = ""
msg = MIMEMultipart('alternative')
msg['Subject'] = "Alert"
msg['From'] = me
msg['To'] = you
html = '<html><body><p>Hi, I have the following alerts for you!</p></body></html>'
part2 = MIMEText(html, 'html')
msg.attach(part2)
# Send the message via gmail's regular server, over SSL - passwords are being sent, afterall
s = smtplib.SMTP_SSL('smtp.gmail.com')
# uncomment if interested in the actual smtp conversation
# s.set_debuglevel(1)
# do the smtp auth; sends ehlo if it hasn't been sent already
s.login(me, my_password)
s.sendmail(me, you, msg.as_string())
s.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment