GNU bug report logs - #34177
smtpmail.el aborts on transient errors

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Brian Sniffen <bts@HIDDEN>; Keywords: moreinfo patch; dated Wed, 23 Jan 2019 12:11:02 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 34177 <at> debbugs.gnu.org:


Received: (at 34177) by debbugs.gnu.org; 9 Jul 2019 18:46:02 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Jul 09 14:46:02 2019
Received: from localhost ([127.0.0.1]:34203 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1hkv7p-0002GD-Q5
	for submit <at> debbugs.gnu.org; Tue, 09 Jul 2019 14:46:02 -0400
Received: from eggs.gnu.org ([209.51.188.92]:58136)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <eliz@HIDDEN>) id 1hkv7o-0002Ac-WF
 for 34177 <at> debbugs.gnu.org; Tue, 09 Jul 2019 14:46:01 -0400
Received: from fencepost.gnu.org ([2001:470:142:3::e]:56403)
 by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <eliz@HIDDEN>)
 id 1hkv7g-0003fY-GI; Tue, 09 Jul 2019 14:45:53 -0400
Received: from [176.228.60.248] (port=1714 helo=home-c4e4a596f7)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <eliz@HIDDEN>)
 id 1hkv7e-0002lR-0w; Tue, 09 Jul 2019 14:45:51 -0400
Date: Tue, 09 Jul 2019 21:45:35 +0300
Message-Id: <83o9233v3k.fsf@HIDDEN>
From: Eli Zaretskii <eliz@HIDDEN>
To: Lars Ingebrigtsen <larsi@HIDDEN>
In-reply-to: <87h87vqd64.fsf@HIDDEN> (message from Lars Ingebrigtsen
 on Tue, 09 Jul 2019 20:24:19 +0200)
Subject: Re: bug#34177: smtpmail.el aborts on transient errors
References: <70A0D375-0530-45D8-B4A4-B7BDF009749D@HIDDEN>
 <87h87vqd64.fsf@HIDDEN>
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 34177
Cc: bts@HIDDEN, 34177 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

> From: Lars Ingebrigtsen <larsi@HIDDEN>
> Date: Tue, 09 Jul 2019 20:24:19 +0200
> Cc: 34177 <at> debbugs.gnu.org
> 
> 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?

IMO, this should at least say in the echo area that it's retrying,
probably with the number of retries.  Bonus points for doing that from
a separate thread or a timer.  smtpmail locks up Emacs too much
already, when the network is busy.




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#34177; Package emacs. Full text available.
Added tag(s) patch. Request was from Lars Ingebrigtsen <larsi@HIDDEN> to control <at> debbugs.gnu.org. Full text available.
Added tag(s) moreinfo. Request was from Lars Ingebrigtsen <larsi@HIDDEN> to control <at> debbugs.gnu.org. Full text available.

Message received at 34177 <at> debbugs.gnu.org:


Received: (at 34177) by debbugs.gnu.org; 9 Jul 2019 18:24:30 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Jul 09 14:24:30 2019
Received: from localhost ([127.0.0.1]:34171 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1hkumy-000780-Ud
	for submit <at> debbugs.gnu.org; Tue, 09 Jul 2019 14:24:30 -0400
Received: from quimby.gnus.org ([80.91.231.51]:51120)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <larsi@HIDDEN>) id 1hkumw-00077q-Un
 for 34177 <at> debbugs.gnu.org; Tue, 09 Jul 2019 14:24:28 -0400
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 <larsi@HIDDEN>)
 id 1hkump-00086j-Kl; Tue, 09 Jul 2019 20:24:22 +0200
From: Lars Ingebrigtsen <larsi@HIDDEN>
To: Brian Sniffen <bts@HIDDEN>
Subject: Re: bug#34177: smtpmail.el aborts on transient errors
References: <70A0D375-0530-45D8-B4A4-B7BDF009749D@HIDDEN>
Date: Tue, 09 Jul 2019 20:24:19 +0200
In-Reply-To: <70A0D375-0530-45D8-B4A4-B7BDF009749D@HIDDEN> (Brian
 Sniffen's message of "Tue, 22 Jan 2019 23:09:08 -0500")
Message-ID: <87h87vqd64.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Spam-Report: Spam detection software, running on the system "quimby.gnus.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 @@CONTACT_ADDRESS@@ for details.
 
 Content preview:  Brian Sniffen <bts@HIDDEN> writes: > smtpmail.el treats
    all return codes over 400 as errors, and aborts. > But RFC 821 and successors
    call the 400-series “transient” errors and > suggest retrying immediately.
    Some mail servers, inc [...] 
 
 Content analysis details:   (-2.9 points, 5.0 required)
 
  pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -1.0 ALL_TRUSTED            Passed through trusted hosts only via SMTP
 -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%
                             [score: 0.0000]
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 34177
Cc: 34177 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Brian Sniffen <bts@HIDDEN> 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))

--=-=-=--




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#34177; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 23 Jan 2019 12:10:34 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jan 23 07:10:34 2019
Received: from localhost ([127.0.0.1]:42100 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gmHMX-0004Sb-9O
	for submit <at> debbugs.gnu.org; Wed, 23 Jan 2019 07:10:34 -0500
Received: from eggs.gnu.org ([209.51.188.92]:53285)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <bts@HIDDEN>) id 1gmA1K-0007IN-Rp
 for submit <at> debbugs.gnu.org; Tue, 22 Jan 2019 23:20:11 -0500
Received: from lists.gnu.org ([209.51.188.17]:43542)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <bts@HIDDEN>) id 1gmA1F-0006g6-FD
 for submit <at> debbugs.gnu.org; Tue, 22 Jan 2019 23:20:05 -0500
Received: from eggs.gnu.org ([209.51.188.92]:35090)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <bts@HIDDEN>) id 1gmA1E-0002hf-L6
 for bug-gnu-emacs@HIDDEN; Tue, 22 Jan 2019 23:20:05 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled
 version=3.3.2
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <bts@HIDDEN>) id 1gm9r6-0000rU-3G
 for bug-gnu-emacs@HIDDEN; Tue, 22 Jan 2019 23:09:37 -0500
Received: from istari.evenmere.org ([136.248.125.194]:56914)
 by eggs.gnu.org with esmtp (Exim 4.71)
 (envelope-from <bts@HIDDEN>) id 1gm9qp-0004pf-Ch
 for bug-gnu-emacs@HIDDEN; Tue, 22 Jan 2019 23:09:26 -0500
Received: by istari.evenmere.org (Postfix, from userid 113)
 id 70B0D1E0067; Tue, 22 Jan 2019 23:09:12 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=evenmere.org;
 s=default; t=1548216552;
 bh=aIrqTTKyxGv9PDoDKJP0e4wYS0it0qLgRJCt8fZaqsY=;
 h=From:Date:Subject:To:From;
 b=xA3ViSV79LxGnra4Ijb83DYERCbcjR/xtV5gt+kDBbp8S2GLSPaegPmlGGx85Gfq8
 uFYfQD9VsV2U1C31NzG9PstT9LkWiTX5WU4Dln3yXm6sNJXavoX7zKJxhFdOkPR+aJ
 zK14fge2SSk6xJcYZbk/3zNuMs7z8nZTW4NhOhJY=
Received: from [192.168.0.34] (pool-108-7-216-63.bstnma.fios.verizon.net
 [108.7.216.63])
 by istari.evenmere.org (Postfix) with ESMTPSA id 345251E0067;
 Tue, 22 Jan 2019 23:09:10 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=evenmere.org;
 s=default; t=1548216550;
 bh=aIrqTTKyxGv9PDoDKJP0e4wYS0it0qLgRJCt8fZaqsY=;
 h=From:Date:Subject:To:From;
 b=OXBO/uW/gfz7cx6SIvD+Akzw7nVSjNGUFPMBMiVPR39lyKVfC+FBiCjFDmrgY1y8L
 F6LtT7YpQqOw8D/YtSlGFy2mmuZ0HpdK70yGkougsmFHqmuoWrJBps31SgWt08hmSt
 yCfrpAwn14CXyyeTUUKjxyKVz5ld/TLbhapv4Lyo=
From: Brian Sniffen <bts@HIDDEN>
Content-Type: text/plain;
	charset=utf-8
Content-Transfer-Encoding: quoted-printable
Mime-Version: 1.0 (1.0)
Date: Tue, 22 Jan 2019 23:09:08 -0500
Subject: smtpmail.el aborts on transient errors
Message-Id: <70A0D375-0530-45D8-B4A4-B7BDF009749D@HIDDEN>
To: bug-gnu-emacs@HIDDEN
X-Mailer: iPad Mail (16D39)
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 136.248.125.194
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Spam-Score: 1.0 (+)
X-Debbugs-Envelope-To: submit
X-Mailman-Approved-At: Wed, 23 Jan 2019 07:10:30 -0500
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -0.0 (/)

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 a=
nd suggest retrying immediately.  Some mail servers, including current MS Ex=
change, 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, bu=
t in general it=E2=80=99s safe to loop for seconds on any command.

--=20
Brian Sniffen=





Acknowledgement sent to Brian Sniffen <bts@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#34177; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Tue, 9 Jul 2019 18:45:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.