[Tutor] Smtplib module

Glen Wheeler wheelege@tsn.cc
Sun, 21 Oct 2001 11:23:26 +1000


 um...

> <..>
>
> :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.
>

  I think you may be getting dictionary and list confused with perhaps an
object which defines it's own str() function?  Have a look at this
interpreter session...

>>> d = ['1', 2, 3]
>>> print d
['1', 2, 3]
>>> print str(d)
['1', 2, 3]
>>> d = {1:2, 3:4}
>>> print d
{3: 4, 1: 2}
>>> print str(d)
{3: 4, 1: 2}
>>>

  Just having a quick squiz at the doc's reveals "If this method does not
throw an exception, it returns a dictionary, with one entry for each
recipient that was refused.".  So if it throws an exception, look in the
docs to find otu more about it, if not then you will get a dict back for
each one which was refused.

  Sorry to nitpick,
  Glen