[issue29539] [smtplib] collect response data for all recipients
David Ford (FirefighterBlu3)
report at bugs.python.org
Sun Feb 12 19:45:25 EST 2017
New submission from David Ford (FirefighterBlu3):
Feature request; collect SMTP response results for all recipients so data likely including the queue ID or SMTP delay expectation can be collected
I propose the keyword "keep_results=False" be added to smtplib.sendmail() to accomplish this. The default value of False maintains the legacy functionality of prior versions. No other changes have been done to smtplib.send_message() pending discussion of the following.
@@ -785,7 +785,7 @@
return (resp, reply)
def sendmail(self, from_addr, to_addrs, msg, mail_options=[],
- rcpt_options=[]):
+ rcpt_options=[], keep_results=False):
"""This command performs an entire mail transaction.
The arguments are:
@@ -797,6 +797,8 @@
mail command.
- rcpt_options : List of ESMTP options (such as DSN commands) for
all the rcpt commands.
+ - keep_results : If True, return a dictionary of recipients and the
+ SMTP result for each.
msg may be a string containing characters in the ASCII range, or a byte
string. A string is encoded to bytes using the ascii codec, and lone
@@ -807,17 +809,20 @@
and each of the specified options will be passed to it. If EHLO
fails, HELO will be tried and ESMTP options suppressed.
- This method will return normally if the mail is accepted for at least
- one recipient. 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.
+ If keep_results is False, this method will return normally if the mail
+ is accepted for at least one recipient. 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. If keep_results is True, this method returns a dictionary
+ of all recipients and the SMTP result whether refused or accepted
+ unless all are refused then the normal exception is raised.
This method may raise the following exceptions:
SMTPHeloError The server didn't reply properly to
the helo greeting.
- SMTPRecipientsRefused The server rejected ALL recipients
- (no mail was sent).
+ SMTPRecipientsRefused The server rejected ALL recipients (no mail
+ was sent).
SMTPSenderRefused The server didn't accept the from_addr.
SMTPDataError The server replied with an unexpected
error code (other than a refusal of
@@ -879,6 +884,10 @@
self._rset()
raise SMTPRecipientsRefused(senderrs)
(code, resp) = self.data(msg)
+ if keep_results:
+ for each in to_addrs:
+ if not each in senderrs:
+ senderrs[each]=(code, resp)
if code != 250:
if code == 421:
self.close()
----------
components: email
messages: 287662
nosy: David Ford (FirefighterBlu3), barry, r.david.murray
priority: normal
severity: normal
status: open
title: [smtplib] collect response data for all recipients
type: enhancement
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29539>
_______________________________________
More information about the Python-bugs-list
mailing list