[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,6 +129,7 @@ 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)
(condition-case signal-data
(if account (if account
(progn (progn
(message "Sending with account for %s" address) (message "Sending with account for %s" address)
@ -143,7 +148,12 @@ This function uses `message-smtpmail-send-it, but sets `smtpmail-smtp-server
(message-smtpmail-send-it))) (message-smtpmail-send-it)))
(if (yes-or-no-p "Sending with default account settings?") (if (yes-or-no-p "Sending with default account settings?")
(message-smtpmail-send-it) (message-smtpmail-send-it)
(message "Sending aborted as requested by user."))))) (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