summaryrefslogtreecommitdiff
path: root/lisp/mail/smtpmail.el
diff options
context:
space:
mode:
authorTassilo Horn <tsdh@gnu.org>2019-09-22 11:02:39 +0200
committerTassilo Horn <tsdh@gnu.org>2019-09-22 11:02:39 +0200
commitaf0642a4cb220f33a43d1380be085bc0b7134bb8 (patch)
treee3b1b57bc42e712c77bd55fc4fc722cf93fe6c66 /lisp/mail/smtpmail.el
parent8992bc7d1b7e7babbf2899b5c45e84b486f504e6 (diff)
parent37a4233a366797360c2f4f475591a3406586bcfb (diff)
downloademacs-scratch/tsdh-vc-list-files.tar.gz
Merge remote-tracking branch 'origin/master' into scratch/tsdh-vc-list-filesscratch/tsdh-vc-list-files
Diffstat (limited to 'lisp/mail/smtpmail.el')
-rw-r--r--lisp/mail/smtpmail.el28
1 files changed, 27 insertions, 1 deletions
diff --git a/lisp/mail/smtpmail.el b/lisp/mail/smtpmail.el
index f6fd1cd65eb..802c9ba788d 100644
--- a/lisp/mail/smtpmail.el
+++ b/lisp/mail/smtpmail.el
@@ -165,6 +165,13 @@ attempt."
:type '(choice regexp (const :tag "None" nil))
:version "27.1")
+(defcustom smtpmail-retries 10
+ "The number of times smtpmail will retry sending when getting transient errors.
+These are errors with a code of 4xx from the SMTP server, which
+mean \"try again\"."
+ :type 'integer
+ :version "27.1")
+
;; End of customizable variables.
@@ -654,10 +661,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 +828,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 smtpmail-retries))
+ (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))