[Tutor] question about headers and smtplib
nephish at gmail.com
Tue Aug 1 21:29:13 CEST 2006
OK, this worked, please disregard my last. The online docs at
python.orgtold me the answer to that one. Between their example and
yours, i am able
to make it work.
thanks a whole bunch !
On 7/31/06, Justin Ezequiel <justin.mailinglists at gmail.com> wrote:
> When I first started with Python, I used MimeWriter to create E-mails.
> Then some mail servers rejected my E-mails.
> Some research (google) indicated (to me) that I needed a MIME-Version
> (Can't recall now if I also needed a Content-Type header.)
> Anyway, more research (Python docs) indicated that I should use the
> email package instead.
> I have been doing so since and have not had reports of anymore rejected
> Hope this helps.
> >>> import email
> >>> from email.MIMENonMultipart import MIMENonMultipart
> >>> from email.Utils import formataddr
> >>> format_addresses = lambda pairs: ', '.join([formataddr(pair) for
> pair in pairs])
> >>> msg = MIMENonMultipart('text', 'plain', charset='us-ascii')
> >>> msg.set_payload('Foo Bar')
> >>> msg.add_header('From', formataddr(('Justin', 'a at b.com')))
> >>> msg.add_header('To', format_addresses([('Justin', 'a at b.com'),
> ('You', 'c at e.com')]))
> >>> print msg.as_string()
> Content-Type: text/plain; charset="us-ascii"
> MIME-Version: 1.0
> From: Justin <a at b.com>
> To: Justin <a at b.com>, You <c at e.com>
> Foo Bar
> Tutor maillist - Tutor at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor