Skip to content

Instantly share code, notes, and snippets.

@pilhokim
Created January 9, 2014 13:18
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 pilhokim/8333987 to your computer and use it in GitHub Desktop.
Save pilhokim/8333987 to your computer and use it in GitHub Desktop.
Excerpted from https://github.com/repoman/rpiips/tree/master/rpiips mail-ip.py is modified to work with my RPi configuration
#!/usr/bin/python
import sys, getopt, subprocess, smtplib, re
# read arugments
def main(argv):
message = ''
output = ''
try:
opts, args = getopt.getopt(argv,"hm:o",["message=","output="])
except getopt.GetoptError:
print 'mail-usbread.py -m <message> -o <output>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'mail-usbread.py -m <message> -o <output>'
sys.exit()
elif opt in ("-m", "--message"):
message = arg
elif opt in ("-o", "--output"):
output = arg
# email auth
to = 'yourgmailaccount@gmail.com'
gmail_user = 'yourgmailaccount@gmail.com'
gmail_password = 'yourgmailpassword'
s = smtplib.SMTP('smtp.gmail.com', 587)
s.ehlo()
s.starttls()
s.ehlo()
s.login(gmail_user, gmail_password)
mail_message = 'Your RPI read the USB data: ' + message
msg = ('Subject: Your RPI USB backup status\n\n%s' % mail_message)
# print msg
msg = ('Subject: Your RPI USB backup status\n\n%s' % mail_message)
# print msg
s.sendmail(gmail_user, to, msg)
s.quit()
if __name__ == "__main__":
main(sys.argv[1:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment