473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Send HTML e-mail in Python?

Max
I am looking for some simple example code on generating SMTP e-mail
messages in Python. I have a script that sends system reports to me at
a central e-mail address, and it works fine using smtplib with plain
text messages. I would like to enhance this script to send HTML
formatted messages instead.

Simply sending a text message with HTML tags does not work. The e-mail
client displays the message as plain text with visible <tags>.
Jul 18 '05 #1
4 1920
mk***@yahoo.com (Max) writes:
Simply sending a text message with HTML tags does not work. The e-mail
client displays the message as plain text with visible <tags>.


You need to add MIME headers to the mail message. I.e., along with the
From: and Subject: lines, add:

MIME-Version: 1.0
Content-Type: text/html

As long as you're using straight ascii, that should be sufficient. If
you want to use extended character sets, things get messy. See <URL:
http://www.cse.ohio-state.edu/cs/Ser.../smtplist.html > for the
RFCs you'll want to look at.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 18 '05 #2
Max wrote:
I am looking for some simple example code on generating SMTP e-mail
messages in Python. I have a script that sends system reports to me at
a central e-mail address, and it works fine using smtplib with plain
text messages. I would like to enhance this script to send HTML
formatted messages instead.

Simply sending a text message with HTML tags does not work. The e-mail
client displays the message as plain text with visible <tags>.


You probably didn't include a "Content-Type: text/html" header in the
RFC822 headers. If that wasn't the problem I do have some code that
works, but I'd have to strip out client-specific features before I
posted it.

regards
Steve
--
http://www.holdenweb.com
http://pydish.holdenweb.com
Holden Web LLC +1 800 494 3119
Jul 18 '05 #3
Google is your friend: python send htlm email

turns up a recipe at ASPN:

http://aspn.activestate.com/ASPN/Coo...n/Recipe/67083

Larry Bates
Max wrote:
I am looking for some simple example code on generating SMTP e-mail
messages in Python. I have a script that sends system reports to me at
a central e-mail address, and it works fine using smtplib with plain
text messages. I would like to enhance this script to send HTML
formatted messages instead.

Simply sending a text message with HTML tags does not work. The e-mail
client displays the message as plain text with visible <tags>.

Jul 18 '05 #4
Max
The solution was I simply missed putting the correct (and
aforementioned) content type in the message header:

msg = ("MIME-Version: 1.0\r\nContent-type: text/html;
charset=utf-8\r\nFrom: %s\r\nTo: %s\r\nSubject: Test Message\r\n" %
(mfrom, mto)) + html
smtp = smtplib.SMTP(smtpserver)
smtp.sendmail(mfrom, mto, msg)

Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bob | last post by:
Seem to have a problem ending a session. I get the following message. Warning: session_start(): Cannot send session cookie - headers already sent by (output started at...
1
by: Kenshin | last post by:
Hey! I have another script where i pull all the information from the database and I want to send it to the person. What they do is they enter in their email, and if the email matches, than it will...
3
by: Kurda Yon | last post by:
Sorry for a very stupid question. Can you tell me what does the following html source does if I press button "Send"? If I read this code by Netscaspe from my local file system and then press...
5
by: Yossi Naggar | last post by:
Hello to everyone, Does anybody know how to send html formatted messages with asp.net? I tried to send such messages with the code below but the content type is wrong. The content type is...
9
by: eswanson | last post by:
I have a web page I need to post a file plus some other fields to it. How can I do this from a asp.net page. I know I can send individual fields to the other page, but how do I send a file to the...
10
by: Sven Huijbrechts | last post by:
Hello, I need to send a couple of "NUL"s -> HEX value "00" on a networkstream.. This is the code we currently use to send string: Dim sendBytes As () =...
5
by: Dan | last post by:
Hi, Is there a way to send information via javascript by redirecting to a page that contains frames? The information that will have to be sent will be the page name of the original page before...
1
by: mubarak basha | last post by:
hi, i wrote the following coding.......... <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Getting...
5
by: trig | last post by:
Please help! I am an ICT teacher at a secondary school and my year 12 (AS Level) group need to create a website where data can be sent from a form to a Microsoft Access database. I am trying...
1
by: steinwaygirl | last post by:
Hi all, I have been searching so hard for the answer to this, hopefully some of you all can help. I have created an HTML file with various forms - also included CSS and some javascript for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.