SMTPLIB : how to add Subject: field ?

Gerhard Häring gh_pythonlist at gmx.de
Mon Jan 28 14:28:55 EST 2002


Le 28/01/02 à 19:32, blackwatch écrivit:
> Hello from France,
> 
> I would like to know how to have the "subject" field filled when I send
> a message with SMTPLIB (I use MacPython 2.2).
> Thanks a lot for your help.

You need to include it in the headers of the email. A complete email
would then look like:

"""
From: me at somewhere.net
To: whoever at somwhereother.
Subject: Sent with smtplib

hi

this is just a test message. bye.
"""

Note the blank line between the headers and the actual message body,
starting with "hi". Oh well, it also should have a Date header and
probably some others. Btw. the From: and To: can AFAIK be anything.
That's why spammers can easily fake them.

As you're using Python 2.2, there's also a nice new module called email
that simplifies constructing and parsing email messages. A complete
example for sending an email (with Subject) can be found at:

    http://www.python.org/doc/current/lib/node389.html

Gerhard
-- 
This sig powered by Python!
Außentemperatur in München: 11.8 °C      Wind: 8.0 m/s




More information about the Python-list mailing list