0

I have a test.html file that I want to send via email(I am refering about the page content). Is there a way for getting the information from the html and sending it as a email? If you have any other ideas please share.

1
  • 1
    you can do so with python or anyother scripting language. Just google there are many examples, all you have to do is to make sure you set Content-type: text/html in email headers so that target will interpret it accordingly. Commented Feb 10, 2012 at 11:12

2 Answers 2

2

Here's a quick and dirty script I just wrote which might be what you're looking for.

https://gist.github.com/1790847

"""
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 <[email protected]>
To: Stuart Powers <[email protected]>
MIME-Version: 1.0
Content-type: text/html
Subject: %s

%s""" %(page, content)


smtpserver = smtplib.SMTP("smtp.gmail.com",587)
smtpserver.starttls()
smtpserver.login("[email protected]",os.environ["GPASS"])
smtpserver.sendmail('[email protected]', ['[email protected]'], message)
Sign up to request clarification or add additional context in comments.

2 Comments

Hi! Thank you for the answer even if I had to manually make lxml from binary file since i didn't find a 2.7 installer, this is what I wanted.
haha, yeah lxml can be a pain to install but make_links_absolute() is pretty handy :) glad to have helped.
1

There are many ways of reading files in python and there are also ways to send emails in python. Why don't you look up the documentation and come back with some coding error ?

1 Comment

Hello, I've look at the documentation, what I am asking is if there is a way to have already a page saved in a html file and import the content to an email and send it. The example I saw is how to build a html email, that will mean i will have to create the html again. Is that the only way?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.