Skip to content

Instantly share code, notes, and snippets.

@dreamspy
Created May 21, 2020 16:35
Show Gist options
  • Save dreamspy/b87024d86c98d985f218f4e758a49c62 to your computer and use it in GitHub Desktop.
Save dreamspy/b87024d86c98d985f218f4e758a49c62 to your computer and use it in GitHub Desktop.
Test SMPT python script
import smtplib
import sys
gmail_user = 'emailaddress@pan.is'
gmail_password = 'password'
sent_from = gmail_user
to = [gmail_user, gmail_user]
subject = 'OMG Super Important Message'
body = 'the body'
email_text = """\
From: %s
To: %s
Subject: %s
%s
""" % (sent_from, ", ".join(to), subject, body)
try:
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_user, gmail_password)
server.sendmail(sent_from, to, email_text)
server.close()
print 'Email sent!'
except:
print 'Something went wrong...'
print "Unexpected error:", sys.exc_info()[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment