print 'Test for New IP Address only' #version 1 - 3-02-2013 SMTPserver = 'outgoing.verizon.net' sender = 'davebodnar@verizon.net' destination = ['bodnar@gmail.com'] USERNAME = "davebodnar" PASSWORD = "pwpwpwpwpwf" # typical values for text_subtype are plain, html, xml text_subtype = 'plain' import sys import os import re os.system("wget http://davebodnar.com/showip2OK2.php") os.system("ls -lhtr") os.system("sudo cp showip2OK2.php ipnow.txt") os.system("rm showip2OK2.php") filename="ipnow.txt" tfile=open(filename) ipnow = tfile.read() tfile.close() filename="ipold.txt" tfile=open(filename) oldip=tfile.read() tfile.close() os.system("sudo cp ipnow.txt ipold.txt") os.system("sudo rm ipnow.txt") if ipnow == oldip: print "same " + oldip else: print "changed " + ipnow +"was " + oldip tosend = ipnow subject = "New IP is now: " + ipnow content="""\ New IP Report From Raspberry Pi """ + ipnow body = "IP was " + oldip + "IP is now " + ipnow from smtplib import SMTP_SSL as SMTP # this invokes the secure SMTP protocol (port 465, uses SSL) # from smtplib import SMTP # use this for standard SMTP protocol (port 25, no encryption) from email.MIMEText import MIMEText try: msg = MIMEText(content, text_subtype) msg['Subject']= subject msg['From'] = sender # some SMTP servers will do this automatically, not all conn = SMTP(SMTPserver) conn.set_debuglevel(False) conn.login(USERNAME, PASSWORD) try: conn.sendmail(sender, destination, msg.as_string()) finally: conn.close() except Exception, exc: sys.exit( "mail failed; %s" % str(exc) ) # give a error message