Smtplib module

Grant Edwards grante at visi.com
Sat Oct 20 21:29:16 EDT 2001


On Sun, 21 Oct 2001 00:14:35 +0200, Gerhard Häring <gh_pythonlist at gmx.de> wrote:
>On Sat, Oct 20, 2001 at 11:41:34PM +0200, A wrote:

>> I want to use smtplib module for sending emails.  Is there any way how
>> I can test a return code, generated by this module, to see if an email
>> was accepting for delivery, for example?
>
>No, there is no way to do this. But this is a "feature" of
>SMTP, not of Python's smtplib.

Sure there is.  There's no way to know if the message was
delivered or read, but you can certainly find out if the SMTP
server accepted it. The documentation for the "sendmail" method
states:

  This method will return normally if the mail is accepted for
  at least one recipient. Otherwise it will throw an exception.
  That is, if this method does not throw an exception, then
  someone should get your mail. If this method does not throw
  an exception, it returns a dictionary, with one entry for
  each recipient that was refused.  Each entry contains a tuple
  of the SMTP error code and the accompanying error message
  sent by the server.

>The only way smtplib is concerned is if the "RCPT TO" command
>fails with 550 "no such user".

According the the smtplib documentation there are two other
different errors that can cause a "sendmail" call to fail.

>Then the sendmail method already returns the address as not
>deliverable to. But at least my mailserver (Postfix) doesn't
>return a 550 in such cases.

That's a "feature" of Postfix: it accepts mail that it can't
deliver.

>There are some other possibilties, but these will only work in some
>relatively rare cases, (finger, SMTP delivery receipts and possibly
>others). But all of these are out of the scope of Python's smtplib.

Not sure what other possiblities/cases to which you refer...

-- 
Grant Edwards                   grante             Yow!  FIRST, I'm covering
                                  at               you with OLIVE OIL and
                               visi.com            PRUNE WHIP!!



More information about the Python-list mailing list