Created on 2017-02-13 00:45 by David Ford (FirefighterBlu3), last changed 2017-02-13 00:45 by David Ford (FirefighterBlu3).
|msg287662 - (view)||Author: David Ford (FirefighterBlu3) (David Ford (FirefighterBlu3)) *||Date: 2017-02-13 00:45|
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()
|2017-02-13 00:45:25||David Ford (FirefighterBlu3)||create|