[New-bugs-announce] [issue16005] smtplib.SMTP().sendmail() and rset()

DDarko report at bugs.python.org
Sun Sep 23 14:21:25 CEST 2012


New submission from DDarko:

I'm trying to send an email as follows:

smtp = smtplib.SMTP(host, port=25)
smtp.ehlo()
smtp.sendmail(from_mail, to_mail, data)

The last line / command calls the raise.
I would like to know the reason why SMTP did not accept my email?
In theory, enough to capture the exception.
However, the exception of the last line returns:
"smtplib.SMTPServerDisconnected: Connection unexpectedly closed"
This is because the smtplib get replies in:
http://hg.python.org/cpython/file/default/Lib/smtplib.py
   767         (code, resp) = self.data(msg)
Then performs:
   769             self.rset()
As a result, the SMTP server disconnects the client. And instead receive info with reason I have information about sudden disconnection.

I do not think it should be reset, and if it is wrapped in a try.

Working snippet:
(code, resp) = self.data(msg)
if code != 250:
    #self.rset()
    raise SMTPDataError(code, resp)
#if we got here then somebody got our mail
return senderrs


This happens on servers mx.google.com

----------
components: Library (Lib)
messages: 171029
nosy: DDarko
priority: normal
severity: normal
status: open
title: smtplib.SMTP().sendmail() and rset()
type: behavior
versions: Python 3.2

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


More information about the New-bugs-announce mailing list