Specifying subject using smtplib

Grant Edwards nobody at nowhere.nohow
Sun Feb 13 03:52:47 CET 2000


On Sun, 06 Feb 2000 22:18:50 GMT, Fredrik Lundh <effbot at telia.com> wrote:
>Jim Severino <jimsev at my-deja.com> wrote:
>> In the smtplib module, the SMTP object's method "sendmail" is formatted
>> like so:
>>
>> sendmail (from_addr, to_addrs, msg[, mail_options, rcpt_options])
>>
>> Can anyone tell me where you specify the message's subject?
>
>in the message itself.
>
>from_addr and to_addrs are commands to the
>mail transport; everything that you want to go
>into the message header should be explicitly put
>into the message.

[...]

>body = string.join((
>    "From: %s" % FROM,
>    "To: %s" % TO,
>    "Subject: %s" % SUBJECT,
>    "",
>    BODY), "\r\n")
>
>print body
>
>server = smtplib.SMTP(HOST)
>server.sendmail(FROM, [TO], body)
>server.quit()

Though it's probably overkill for just adding From: To: and
Subject: headers, the MimeWriter package will construct the
message headers and the message body for you.  It's especially
useful if you want to do things like multipart messages and
attachments.

-- 
Grant Edwards                   grante             Yow!  If this was a SWEDISH
                                  at               MOVIE, I'd take off your
                               visi.com            GO-GO BOOTS!!



More information about the Python-list mailing list