Mailing List Archive

smtp module
I have pretty much figured out how to use the module but I can't seem
set the subject or the from of the bcc etc....

please tell me how to do it?
smtp module [ In reply to ]
Philip C. <pjc_2@geocities.com> wrote:
: I have pretty much figured out how to use the module but I can't seem
: set the subject or the from of the bcc etc....

: please tell me how to do it?

You need to include the SMTP headers in the message itself.

from smtplib import SMTP
fromaddr = 'arcege@shore.net'
toaddr = 'python-list@python.org'
message = '''\
From: %(fromaddr)s
To: %(toaddr)s
Subject: Re: smtp module
Bcc: %(fromaddr)s
Reply-to: %(fromaddr)s

Philip C. <pjc_2geocities.com> wrote:
: I have pretty much figured out how to use the module but I can't seem
: set the subject or the from of the bcc etc....

: please tell me how to do it?
''' % locals()

SMTP('mailhost').sendmail(fromaddr, [toaddr], message)

The protocol for SMTP requires that the headers are included.

-Arcege
smtp module [ In reply to ]
"Michael P. Reilly" <arcege@shore.net> writes:

> Philip C. <pjc_2@geocities.com> wrote:
> : I have pretty much figured out how to use the module but I can't seem
> : set the subject or the from of the bcc etc....

[snip]

> The protocol for SMTP requires that the headers are included.

Actually, Bcc: shouldn't be, even if some mail servers seem to work as
you expect. If you want to Bcc: to someone, add their address to the
envelope recipients, but not the message:

>>> fromaddr = 'c.evans@clear.net.nz'
>>> toaddr = 'eggs@example.com'
>>> msg = '''From: Carey Evans <c.evans@clear.net.nz>
To: Spam, spam, spam, eggs and spam <eggs@example.com>
Subject: Something completely different

Blah, blah, blah...'''
>>> s = smtplib.SMTP('localhost')
>>> s.sendmail(fromaddr, [fromaddr, toaddr], msg)

--
Carey Evans http://home.clear.net.nz/pages/c.evans/

"I'm not a god. I've just been misquoted."