Problems with headers in email.message

Slippy slippy.lane at googlemail.com
Sat Aug 4 17:38:23 CEST 2007


Hi, python newbie, struggling to learn here. I'm trying to write a
simple program which posts messages to my google group (via email).
I'm using smtplib, email and email.message to build and send a
message, but all the header attributes are appearing in the message
body, so my messages are arriving with loads of junk in the body, no
subject line and only the skinniest of headers. I know I'm doing
something wrong, but I don't know what...

Here's a simplification of what I'm doing....essentially, I've taken
from what I've learned at
http://codeidol.com/python/python3/Client-Side-Scripting/pymail-A-Console-Based-Email-Client/

-------------Snip Here-------------Snip Here-------------Snip
Here-------------
import smtplib, email
from email.message import Message
m = Message( )
m['From'] = 'Slippy <user at myemail.com>'
m['To'] = 'mygroup at googlegroups.com'
m['Subject'] = 'A Test Message'
m.set_payload('This is a test email. Please ignore')
s = smtplib.SMTP('smtp.myemail.com')
failed =
s.sendmail('user at myemail.com','mygroup at googlegroups.com',str(m))
if failed:
 print 'Message sending failed.'
else:
 print 'Message sent.'
print 'Bye.'
-------------Snip Here-------------Snip Here-------------Snip
Here-------------

Now, I get all the right responses, and the message sends ok. I go and
check my inbox, and the message is there, but the From, To and Subject
lines I created (as well as a preceding blank line and a "From nobody"
line) are in the message body, followed by the body text.

How do I assign values to the header?

I'd appreciate any help anyone can give me with this.




More information about the Python-list mailing list