diff --git a/gnus.el b/gnus.el index 5a2ef3b..adfb004 100644 --- a/gnus.el +++ b/gnus.el @@ -129,58 +129,6 @@ (advice-add 'mml-attach-file :around #'db/mml-attach-file--go-to-eob) - -;;; SMTP configuration - -(require 'smtpmail) -(require 'starttls) - -(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 send-mail-function 'smtpmail-send-it - smtpmail-stream-type 'starttls - smtpmail-smtp-service 587 - starttls-use-gnutls t - starttls-extra-arguments '("--strict-tofu") - smtpmail-smtp-server (nth 3 (car db/mail-accounts)) - smtpmail-smtp-user (nth 6 (car db/mail-accounts))) - -(defun db/set-smtp-server-from-header (orig-fun &rest args) - "Choose smtp-settings dynamically, based on the From: header -entry of the current mail." - (require 'mail-extr) - (let* ((from (or (save-restriction - (message-narrow-to-headers) - (mail-fetch-field "From")) - user-mail-address)) - (address (cadr (mail-extract-address-components from))) - (account (assoc address db/mail-accounts))) - (message "Using address: %s" address) - (if account - (progn - (message "Sending with account for %s" address) - ;; XXX: these calls to `nth’ should be abstracted away - (let ((smtpmail-smtp-server (nth 3 account)) - (smtpmail-stream-type (nth 4 account)) - (smtpmail-smtp-service (nth 5 account)) - (smtpmail-smtp-user (nth 6 account))) - (apply orig-fun args))) - (progn - (message "Sending with default account settings") - (apply orig-fun args))))) - -(advice-add 'smtpmail-via-smtp - :around #'db/set-smtp-server-from-header) - -(setq smtpmail-debug-info t) - ;;; t diff --git a/init.el b/init.el index 8fd4665..3036229 100644 --- a/init.el +++ b/init.el @@ -1226,7 +1226,8 @@ parameters for one particular email address." db/signencrypt-message-when-possible db/gnus-save-newsrc-with-whitespace-1 db/gnus-summary-open-Link - db/gnus-html-mime-part-to-org)) + db/gnus-html-mime-part-to-org + db/set-smtp-server-from-header)) (use-package bbdb :commands (bbdb-search-name bbab-initialize bbdb-mua-auto-update-init bbdb-save) @@ -1528,8 +1529,7 @@ parameters for one particular email address." gnus-group-mode-map) (bind-key "C-" #'db/gnus-summary-open-Link gnus-summary-mode-map) - (bind-key "C-" #'db/gnus-summary-open-Link gnus-article-mode-map) -)) + (bind-key "C-" #'db/gnus-summary-open-Link gnus-article-mode-map))) (use-package mm-decode :init (setq mm-text-html-renderer 'shr @@ -1585,6 +1585,32 @@ parameters for one particular email address." :init (progn (setq notmuch-fcc-dirs nil))) +(use-package smtpmail + :defer t + :init (setq send-mail-function 'smtpmail-send-it + smtpmail-stream-type 'starttls + smtpmail-smtp-service 587 + smtpmail-debug-info t) + :config (progn + ;; Dynamically set smtpmail variables when sending mail + (advice-add 'smtpmail-via-smtp + :around #'db/set-smtp-server-from-header) + + ;; 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))))))) + +(use-package starttls + :defer t + :init (setq starttls-use-gnutls t + starttls-extra-arguments '("--strict-tofu"))) + ;; * Crypto diff --git a/site-lisp/db-mail.el b/site-lisp/db-mail.el index da94d6a..5f69fd4 100644 --- a/site-lisp/db-mail.el +++ b/site-lisp/db-mail.el @@ -108,5 +108,29 @@ METHOD specifies the encrypt method used. Can be either (with-current-buffer "*Shell Command Output*" (kill-ring-save (point-min) (point-max))))) +(defun db/set-smtp-server-from-header (orig-fun &rest args) + "Choose smtp-settings dynamically, based on the From: header +entry of the current mail." + (require 'mail-extr) + (let* ((from (or (save-restriction + (message-narrow-to-headers) + (mail-fetch-field "From")) + user-mail-address)) + (address (cadr (mail-extract-address-components from))) + (account (assoc address db/mail-accounts))) + (message "Using address: %s" address) + (if account + (progn + (message "Sending with account for %s" address) + ;; XXX: these calls to `nth’ should be abstracted away + (let ((smtpmail-smtp-server (nth 3 account)) + (smtpmail-stream-type (nth 4 account)) + (smtpmail-smtp-service (nth 5 account)) + (smtpmail-smtp-user (nth 6 account))) + (apply orig-fun args))) + (progn + (message "Sending with default account settings") + (apply orig-fun args))))) + (provide 'db-mail) ;;; db-mail ends here