Created
March 16, 2018 01:41
-
-
Save MZachmann/96f6d7ab42bdaebe93712872a062ffb3 to your computer and use it in GitHub Desktop.
Trivial send mail example to show Raspberry PI -> GMail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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