Created
January 9, 2014 13:18
-
-
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
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
#!/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