]> git.eshelyaron.com Git - emacs.git/commitdiff
Try resending when getting a transient 4xx SMTP code
authorLars Ingebrigtsen <larsi@gnus.org>
Mon, 16 Sep 2019 21:45:34 +0000 (23:45 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Mon, 16 Sep 2019 21:49:30 +0000 (23:49 +0200)
* lisp/mail/smtpmail.el (smtpmail-via-smtp): Try resending when
getting a transient error message (bug#34177).

etc/NEWS
lisp/mail/smtpmail.el

index 12182694d1d707402db9f01429c3ab6e2ef00a05..adb2b642ba913ef65269c980a25429322a5772fa 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1162,6 +1162,10 @@ defining new 'cl-defmethod' of 'smtpmail-try-auth-method'.
 attempt when communicating with the SMTP server(s), the
 'smtpmail-servers-requiring-authorization' variable can be used.
 
+---
+*** smtpmail will now try resending mail when getting a transient 4xx
+error message from the SMTP server.
+
 ** Footnote mode
 
 *** Support Hebrew-style footnotes
index f6fd1cd65eb8d330652ee622cc01c2ebaf3caa32..57913c1f0f03cf6a7dead36b742d278ea3d67daf 100644 (file)
@@ -654,10 +654,12 @@ Returns an error if the server cannot be contacted."
              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)
@@ -819,6 +821,23 @@ Returns an error if the server cannot be contacted."
               ((smtpmail-ok-p (setq result (smtpmail-read-response process)))
                ;; Success.
                )
+               ((and (numberp (car result))
+                     (<= 400 (car result) 499)
+                     (< send-attempts 10))
+                (message "Got transient error code %s when sending; retrying attempt %d..."
+                         (car result) send-attempts)
+                ;; 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)
+                (sleep-for 1)
+               (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))