[Tutor] Smtplib module

Sheila King sheila@thinkspot.net
Sat, 20 Oct 2001 15:06:38 -0700


Doh! there is a mistake in the script that I noticed, right after I
clicked on "send". Read on:

On Sat, 20 Oct 2001 15:00:22 -0700, Sheila King <sheila@thinkspot.net>
wrote about Re: [Tutor] Smtplib module:

:import smtplib
:
:message = """\
:To: me@mydomain.com
:From: me@mydomain.com
:Subject: testing smtp response
:Date: Sat, Oct 20 2001 15:00 -0700
:
:Here is the message body.
:"""
:
:SENDER = 'me@mydomain'
:RECIPIENT = 'me@mydomain'
:
:server = smtplib.SMTP('localhost')
:response = server.sendmail(SENDER, RECIPIENT, message)
:server.close()
:
:print response


That last line above needs to be:

print str(response)

I believe if you check the docs for the smtplib module, you will find
that the response that is returned is a (?) list or dictionary of the
response for each SMTP envelope recipient. Since response isn't a
string, you can't print it. However, you can convert the response to a
string, or write special code to handle the dictionary/list (whichever
it is), and parse the individual results.

For my needs, which are not that complex at the moment, I just convert
it to a string and write it to a log.

HTH,

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/