[Mail] Move SMTP error handling code directly to ‘db/smtpmail-send-it’

This commit is contained in:
Daniel Borchmann 2019-02-10 19:55:25 +01:00
parent 0d81c7fa0b
commit b8912ae08d
Signed by: exot
GPG Key ID: 4F63DB96D45AA9C6
2 changed files with 31 additions and 31 deletions

12
init.el
View File

@ -1591,17 +1591,7 @@
:defer t :defer t
:init (setq smtpmail-stream-type 'starttls :init (setq smtpmail-stream-type 'starttls
smtpmail-smtp-service 587 smtpmail-smtp-service 587
smtpmail-debug-info t) smtpmail-debug-info t))
:config (progn
;; Show trace buffer when something goes wrong
(defadvice smtpmail-send-it (around display-trace-buffer disable)
"If an error is signalled, display the process buffer."
(condition-case signals-data
ad-do-it
(error (shrink-window-if-larger-than-buffer
(display-buffer (get-buffer (format "*trace of SMTP session to %s*"
smtpmail-smtp-server))))
(signal (car signals-data) (cdr signals-data)))))))
(setq starttls-use-gnutls t (setq starttls-use-gnutls t
starttls-extra-arguments '("--strict-tofu")) starttls-extra-arguments '("--strict-tofu"))

View File

@ -117,7 +117,11 @@ will also be recognized when sending mail."
(defun db/smtpmail-send-it () (defun db/smtpmail-send-it ()
"Send prepared message in current buffer. "Send prepared message in current buffer.
This function uses `message-smtpmail-send-it, but sets `smtpmail-smtp-server, `smtpmail-stream-type, `smtpmail-smtp-service, and `smtpmail-smtp-user based on the entry of the \"From: \" header and the value of `db/mail-accounts." This function uses `message-smtpmail-send-it, but sets
`smtpmail-smtp-server, `smtpmail-stream-type,
`smtpmail-smtp-service, and `smtpmail-smtp-user based on the
entry of the \"From: \" header and the value of
`db/mail-accounts."
(let* ((from (or (save-restriction (let* ((from (or (save-restriction
(message-narrow-to-headers) (message-narrow-to-headers)
(mail-fetch-field "From")) (mail-fetch-field "From"))
@ -125,25 +129,31 @@ This function uses `message-smtpmail-send-it, but sets `smtpmail-smtp-server
(address (cadr (mail-extract-address-components from))) (address (cadr (mail-extract-address-components from)))
(account (assoc address db/mail-accounts))) (account (assoc address db/mail-accounts)))
(message "Using address: %s" address) (message "Using address: %s" address)
(if account (condition-case signal-data
(progn (if account
(message "Sending with account for %s" address) (progn
;; XXX: these calls to `nth should be abstracted away (message "Sending with account for %s" address)
(let ((smtpmail-smtp-server (nth 3 account)) ;; XXX: these calls to `nth should be abstracted away
(smtpmail-stream-type (nth 4 account)) (let ((smtpmail-smtp-server (nth 3 account))
(smtpmail-smtp-service (nth 5 account)) (smtpmail-stream-type (nth 4 account))
(smtpmail-smtp-user (nth 6 account))) (smtpmail-smtp-service (nth 5 account))
(cl-assert (cl-notany #'null (list smtpmail-smtp-server (smtpmail-smtp-user (nth 6 account)))
smtpmail-stream-type (cl-assert (cl-notany #'null (list smtpmail-smtp-server
smtpmail-smtp-service smtpmail-stream-type
smtpmail-smtp-user)) smtpmail-smtp-service
t smtpmail-smtp-user))
"Settings %s for sending mail are not complete for account %s." t
address) "Settings %s for sending mail are not complete for account %s."
(message-smtpmail-send-it))) address)
(if (yes-or-no-p "Sending with default account settings?") (message-smtpmail-send-it)))
(message-smtpmail-send-it) (if (yes-or-no-p "Sending with default account settings?")
(message "Sending aborted as requested by user."))))) (message-smtpmail-send-it)
(message "Sending aborted as requested by user.")))
;; in case of error, display the SMTP trace buffer
(error (shrink-window-if-larger-than-buffer
(display-buffer (get-buffer (format "*trace of SMTP session to %s*"
smtpmail-smtp-server))))
(signal (car signal-data) (cdr signal-data))))))
;; Setting other Gnus accounts ;; Setting other Gnus accounts