Philippe C. Martin wrote:
Hi,

I am testing the smtp module and have the following question:

in the code below (taken from net sample) prior to adding the "Subject:"
field, the email client found the "From" and the "To". Without the
"Subject:" field on I get this:

Email client = Evolution: the "From" field is blank
Email client = KMail: the "To" field is blank

Any clue ?

It' very easy to create email messages with the email module.

>>> from email.Message import Message
>>> fromaddr = '[EMAIL PROTECTED]'
>>> to = '[EMAIL PROTECTED]'
>>> msg = Message()
>>> msg['Subject'] = 'From Python'
>>> msg['From'] = fromaddr
>>> msg['To'] = to
>>> body = "This is the message content"
>>> msg.set_payload(body)

Thats all. Though some smtp servers needs a Date header too, to work.

>>> from time import gmtime, strftime
>>> msg['Date'] = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())

Sending the message via the smtp module is even simpler.

>>> import smtplib
>>> server = smtplib.SMTP('localhost')
>>> server.sendmail(fromaddr, [to], msg.as_string())
>>> server.quit()


--

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to