sheila at spamcop.net
Sun Oct 21 02:32:45 CEST 2001
On Sun, 21 Oct 2001 00:14:35 +0200, Gerhard Häring
<gh_pythonlist at gmx.de> wrote in comp.lang.python in article
<mailman.1003616181.19894.python-list at python.org>:
: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
I am very surprised at this response.
This same inquiry was also posted to the Python Tutor mailing list, and
I answered in the affirmative. Here is the message I posted (with a
> To: discuss at sendme.cz
> Subject: Re: [Tutor] Smtplib module
> From: Sheila King <sheila at thinkspot.net>
> Date: Sat, 20 Oct 2001 15:00:22 -0700
> Cc: tutor at python.org
> On Sat, 20 Oct 2001 23:41:34 +0200, "A" <export at bmatrading.com> wrote
> about [Tutor] Smtplib module:
> :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?
> :Thank you for help.
> import smtplib
> message = """\
> To: me at mydomain.com
> From: me at mydomain.com
> Subject: testing smtp response
> Date: Sat, Oct 20 2001 15:00 -0700
> Here is the message body.
> SENDER = 'me at mydomain'
> RECIPIENT = 'me at mydomain'
> server = smtplib.SMTP('localhost')
> response = server.sendmail(SENDER, RECIPIENT, message)
> print str(response)
> # I think the above code is correct, but I didn't test-run it.
Was I mistaken? I thought the above is a correct method for determining
the server's response. And, in fact, I use this method in some scripts
that I run. (I've written a moderator-approval bot for a Usenet
newsgroup, and the bot is currently in production...despite a couple of
bugs. It uses the smtplib and the nntplib, which employ similar methods
for reporting server response.)
:The only way smtplib is concerned is if the "RCPT TO" command fails with
:550 "no such user". 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.
: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.
More information about the Python-list