#!/usr/bin/env python import sys import os import re import urllib, urllib2 # Import smtplib for the actual sending function import smtplib # Import the email modules we'll need from email.MIMEText import MIMEText # TODO: YOUR_EMAIL = "sillyman@gmail.com" YOUR_PW = "1sillyman" def anonymousUrlOpen(url): """ gets a page but spoofs headers """ user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' headers = { 'User-Agent' : user_agent } request = urllib2.Request(url, headers=headers) return urllib2.urlopen(request).read() def sendmail(fromaddr, toaddrs, subject, body, subtype="plain"): if not type(toaddrs) == list: toaddrs = [toaddrs] msg = MIMEText(body, subtype) msg['Subject'] = subject msg['From'] = fromaddr msg['To'] = ", ".join(toaddrs) msg = msg.as_string() #print "Message length is " + repr(len(msg)) print '------' print "Message being sent:", msg print '------' # for some reason, I am now getting from google a "temporary # authentication error" when I try the login() command. Redoing # all of this from the beginning seems to work after a time # or two # (454, '5.7.0 Temporary authentication failure 8sm2462988nzn') numTries = 0 while numTries < 10: try: smtphost = "smtp.gmail.com" #port = 465 port = 587 server = smtplib.SMTP(smtphost, port) server.set_debuglevel(0) print server.ehlo(smtphost) print server.starttls() print server.ehlo(smtphost) print "---" server.login(YOUR_EMAIL, YOUR_PW) server.sendmail(fromaddr, toaddrs, msg) server.close() print "Sent!" break except Exception, e: print e numTries += 1 print "Retry #", numTries def gmailCache(url): fromAddr = "GmailCacher" toAddr = '"%s"' % YOUR_EMAIL # get the webpage body = anonymousUrlOpen(url) # scrape the title m = re.search("