From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#34177: smtpmail.el aborts on transient errors Date: Tue, 09 Jul 2019 20:24:19 +0200 Message-ID: <87h87vqd64.fsf@mouse.gnus.org> References: <70A0D375-0530-45D8-B4A4-B7BDF009749D@evenmere.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="247563"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 34177@debbugs.gnu.org To: Brian Sniffen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jul 09 20:26:23 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hkuop-0012FW-Jw for geb-bug-gnu-emacs@m.gmane.org; Tue, 09 Jul 2019 20:26:23 +0200 Original-Received: from localhost ([::1]:52688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkuoo-0000Op-4p for geb-bug-gnu-emacs@m.gmane.org; Tue, 09 Jul 2019 14:26:22 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59105) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkund-0008R9-L5 for bug-gnu-emacs@gnu.org; Tue, 09 Jul 2019 14:25:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkunY-0003QP-BF for bug-gnu-emacs@gnu.org; Tue, 09 Jul 2019 14:25:06 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:53589) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hkunW-0003PL-DH for bug-gnu-emacs@gnu.org; Tue, 09 Jul 2019 14:25:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hkunW-00079D-4I for bug-gnu-emacs@gnu.org; Tue, 09 Jul 2019 14:25:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 09 Jul 2019 18:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34177 X-GNU-PR-Package: emacs Original-Received: via spool by 34177-submit@debbugs.gnu.org id=B34177.156269667027415 (code B ref 34177); Tue, 09 Jul 2019 18:25:02 +0000 Original-Received: (at 34177) by debbugs.gnu.org; 9 Jul 2019 18:24:30 +0000 Original-Received: from localhost ([127.0.0.1]:34171 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hkumy-000780-Ud for submit@debbugs.gnu.org; Tue, 09 Jul 2019 14:24:30 -0400 Original-Received: from quimby.gnus.org ([80.91.231.51]:51120) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hkumw-00077q-Un for 34177@debbugs.gnu.org; Tue, 09 Jul 2019 14:24:28 -0400 Original-Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=marnie) by quimby.gnus.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hkump-00086j-Kl; Tue, 09 Jul 2019 20:24:22 +0200 In-Reply-To: <70A0D375-0530-45D8-B4A4-B7BDF009749D@evenmere.org> (Brian Sniffen's message of "Tue, 22 Jan 2019 23:09:08 -0500") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:162538 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Brian Sniffen writes: > smtpmail.el treats all return codes over 400 as errors, and aborts. > But RFC 821 and successors call the 400-series =E2=80=9Ctransient=E2=80= =9D errors and > suggest retrying immediately. Some mail servers, including current MS > Exchange, use 400-series errors for load limiting. The user can just > repeat C-c C-c until the mail goes through... or Emacs SMTPmail could > loop until the server accepts it. > > Retrying is a little tricky in the case of multipart commands like > LOGIN, but in general it=E2=80=99s safe to loop for seconds on any comman= d. This is what RFC 5321 says: https://tools.ietf.org/html/rfc5321#section-4.2.1 4yz Transient Negative Completion reply The command was not accepted, and the requested action did not occur. However, the error condition is temporary, and the action may be requested again. The sender should return to the beginning of the command sequence (if any). It is difficult to assign a meaning to "transient" when two different sites (receiver- and sender-SMTP agents) must agree on the interpretation. Each reply in this category might have a different time value, but the SMTP client SHOULD try again. A rule of thumb to determine whether a reply fits into the 4yz or the 5yz category (see below) is that replies are 4yz if they can be successful if repeated without any change in command form or in properties of the sender or receiver (that is, the command is repeated identically and the receiver does not put up a new implementation). So, indeed, smtpmail SHOULD try resending when given a 4xx response code... but presumably not forever, either. It's a bit difficult to test, though. Does the following patch work for you? --=20 (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=retry.patch diff --git a/lisp/mail/smtpmail.el b/lisp/mail/smtpmail.el index 741c4393e6..d9930491d9 100644 --- a/lisp/mail/smtpmail.el +++ b/lisp/mail/smtpmail.el @@ -658,10 +658,12 @@ smtpmail-user-mail-address user-mail-address)))) (defun smtpmail-via-smtp (recipient smtpmail-text-buffer - &optional ask-for-password) + &optional ask-for-password + send-attempts) (unless smtpmail-smtp-server (smtpmail-query-smtp-server)) (let ((process nil) + (send-attempts (or send-attempts 1)) (host (or smtpmail-smtp-server (error "`smtpmail-smtp-server' not defined"))) (port smtpmail-smtp-service) @@ -817,6 +819,20 @@ smtpmail-via-smtp ((smtpmail-ok-p (setq result (smtpmail-read-response process))) ;; Success. ) + ((and (numberp (car result)) + (<= 400 (car result) 499) + (< send-attempts 10)) + ;; Retry on getting a transient 4xx code; see + ;; https://tools.ietf.org/html/rfc5321#section-4.2.1 + (ignore-errors + (smtpmail-send-command process "QUIT") + (smtpmail-read-response process)) + (delete-process process) + (setq process nil) + (throw 'done + (smtpmail-via-smtp recipient smtpmail-text-buffer + ask-for-password + (1+ send-attempts)))) ((and auth-mechanisms (not ask-for-password) (eq (car result) 530)) --=-=-=--