[issue16005] smtplib.SMTP().sendmail() and rset()

DDarko report at bugs.python.org
Sun Sep 23 19:21:32 CEST 2012


DDarko added the comment:

I do not understand why at all reset is performed ?
If moments later raise is done.

If someone despite error SMTPSenderRefused, SMTPRecipientsRefused or SMTPDataError  will still want to maintain a connection and use other data with session is likely he will call SMTP().rset() manually.

In my opinion, the most frequent use of the library are:

smtp = smtplib.SMTP(host, port=25)
smtp.ehlo()
try:
    smtp.sendmail(from_mail, to_mail, data)
except Exception as e:
    print(e)

smtp.quit()


If you wish to use session despite the error:
smtp = smtplib.SMTP(host, port=25)
smtp.ehlo()
for to_mail in mail_list:
    try:
        smtp.sendmail(from_mail, to_mail, data)
    except smtplib.SMTPRecipientsRefused as e:
        smtp.rset()
        print(e)

smtp.quit()

If we do not handle exception, reset does not matter.


IMHO patch should look like this:
http://hg.python.org/cpython/file/default/Lib/smtplib.py
745d744
<             self.rset()
756d754
<             self.rset()
760d757
<             self.rset()

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16005>
_______________________________________


More information about the Python-bugs-list mailing list