Skip to content

Instantly share code, notes, and snippets.

@sente
Created February 10, 2012 16:53
Show Gist options
  • Save sente/1790847 to your computer and use it in GitHub Desktop.
Save sente/1790847 to your computer and use it in GitHub Desktop.
send the content of an webpage as an HTML email
"""
this is a quick and dirty script to send HTML email - emphasis on dirty :)
python emailpage.py http://www.sente.cc
made to answer: http://stackoverflow.com/questions/9226719/sending-a-html-file-via-python
Stuart Powers
"""
import lxml.html
import smtplib
import sys
import os
page = sys.argv[1] #the webpage to send
root = lxml.html.parse(page).getroot()
root.make_links_absolute()
content = lxml.html.tostring(root)
message = """From: Stuart Powers <stuart.powers@gmail.com>
To: Stuart Powers <stuart.powers@gmail.com>
MIME-Version: 1.0
Content-type: text/html
Subject: %s
%s""" %(page, content)
smtpserver = smtplib.SMTP("smtp.gmail.com",587)
smtpserver.starttls()
smtpserver.login("stuart.powers@gmail.com",os.environ["GPASS"])
smtpserver.sendmail('stuart.powers@gmail.com', ['stuart.powers@gmail.com'], message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment