This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author David Ford (FirefighterBlu3)
Recipients David Ford (FirefighterBlu3), barry, r.david.murray
Date 2017-02-13.00:45:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1486946725.6.0.180199923995.issue29539@psf.upfronthosting.co.za>
In-reply-to
Content
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()
History
Date User Action Args
2017-02-13 00:45:25David Ford (FirefighterBlu3)setrecipients: + David Ford (FirefighterBlu3), barry, r.david.murray
2017-02-13 00:45:25David Ford (FirefighterBlu3)setmessageid: <1486946725.6.0.180199923995.issue29539@psf.upfronthosting.co.za>
2017-02-13 00:45:25David Ford (FirefighterBlu3)linkissue29539 messages
2017-02-13 00:45:24David Ford (FirefighterBlu3)create