Skip to content

Instantly share code, notes, and snippets.

@MZachmann
Created March 16, 2018 01:41
Show Gist options
  • Save MZachmann/96f6d7ab42bdaebe93712872a062ffb3 to your computer and use it in GitHub Desktop.
Save MZachmann/96f6d7ab42bdaebe93712872a062ffb3 to your computer and use it in GitHub Desktop.
Trivial send mail example to show Raspberry PI -> GMail
import smtplib
# start talking to the SMTP server for Gmail
s = smtplib.SMTP(‘smtp.gmail.com’, 587)
s.starttls()
s.ehlo()
# now login as my gmail user
username=’myname’
password=’mypassword’
s.login(username,password)
# the email objects
replyto=’myname@gmail.com’ # where a reply to will go
sendto=[‘firstsend@gmail.com’,’nextsend@gmail.com’] # list to send to
sendtoShow=’me@me.com’ # what shows on the email as send to
subject=’Test from pysmtp’ # subject line
content=”Hello, this is a test of the system.\nHows it going\nMe” # content
# compose the email. probably should use the email python module
mailtext=’From: ‘+replyto+’\nTo: ‘+sendtoShow+’\n’
mailtext=mailtext+’Subject:’+subject+’\n’+content
# send the email
s.sendmail(replyto, sendto, mailtext)
# we’re done
rslt=s.quit()
# print the result
print(‘Sendmail result=’ + str(rslt[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment