[Mail] Turn advice on how to send mail into a proper function
More concretely, ‘db/set-smtp-server-from-header’ is now called ‘db/smtpmail-send-it’, and the latter can be used as a value for ‘send-mail-function’.
This commit is contained in:
parent
8864a5bffe
commit
0d81c7fa0b
10
init.el
10
init.el
|
@ -1201,14 +1201,14 @@
|
||||||
;; * Mail
|
;; * Mail
|
||||||
|
|
||||||
(use-package db-mail
|
(use-package db-mail
|
||||||
:commands (db/public-key
|
:commands (db/smtpmail-send-it
|
||||||
|
db/public-key
|
||||||
db/encryption-possible-p
|
db/encryption-possible-p
|
||||||
db/message-recipients
|
db/message-recipients
|
||||||
db/signencrypt-message-when-possible
|
db/signencrypt-message-when-possible
|
||||||
db/gnus-save-newsrc-with-whitespace-1
|
db/gnus-save-newsrc-with-whitespace-1
|
||||||
db/gnus-summary-open-Link
|
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
|
|
||||||
db/gnus-demon-scan-news-on-level-2
|
db/gnus-demon-scan-news-on-level-2
|
||||||
db/mml-attach-file--go-to-eob))
|
db/mml-attach-file--go-to-eob))
|
||||||
|
|
||||||
|
@ -1585,7 +1585,7 @@
|
||||||
:around #'db/mml-attach-file--go-to-eob)))
|
:around #'db/mml-attach-file--go-to-eob)))
|
||||||
|
|
||||||
(setq notmuch-fcc-dirs nil
|
(setq notmuch-fcc-dirs nil
|
||||||
send-mail-function 'smtpmail-send-it)
|
send-mail-function #'db/smtpmail-send-it)
|
||||||
|
|
||||||
(use-package smtpmail
|
(use-package smtpmail
|
||||||
:defer t
|
:defer t
|
||||||
|
@ -1593,10 +1593,6 @@
|
||||||
smtpmail-smtp-service 587
|
smtpmail-smtp-service 587
|
||||||
smtpmail-debug-info t)
|
smtpmail-debug-info t)
|
||||||
:config (progn
|
: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
|
;; Show trace buffer when something goes wrong
|
||||||
(defadvice smtpmail-send-it (around display-trace-buffer disable)
|
(defadvice smtpmail-send-it (around display-trace-buffer disable)
|
||||||
"If an error is signalled, display the process buffer."
|
"If an error is signalled, display the process buffer."
|
||||||
|
|
|
@ -18,17 +18,15 @@
|
||||||
|
|
||||||
;; When sending mail, `db/mail-accounts’ is used to determine settings of the
|
;; When sending mail, `db/mail-accounts’ is used to determine settings of the
|
||||||
;; relevant variables from `smtpmail’ based on the current value of the "From: "
|
;; relevant variables from `smtpmail’ based on the current value of the "From: "
|
||||||
;; header entry in the mail. If this header entry is set correctly, send
|
;; header entry in the mail. If this header entry is set correctly, then
|
||||||
;; `db/set-smtp-server-from-header’ will set these variables automatically. To
|
;; `db/smtpmail-send-it’ will set these variables automatically. To make this
|
||||||
;; make this work, however, two things have to be done:
|
;; work, however, two things have to be done:
|
||||||
;;
|
;;
|
||||||
;; - Ensure that the "From: " header is set correctly. In Gnus this can be done
|
;; - Ensure that the "From: " header is set correctly. In Gnus this can be done
|
||||||
;; by configuring `gnus-posting-style’ accordingly.
|
;; by configuring `gnus-posting-style’ accordingly.
|
||||||
;;
|
;;
|
||||||
;; - Make sure `db/set-smtp-server-from-header’ is called when sending mail.
|
;; - Make sure `db/smtpmail-send-it’ is called when sending mail. For this set
|
||||||
;; Currently, this function is written to be added as an around advice for
|
;; the value `send-mail-function’ to `db/smtpmail-send-it’.
|
||||||
;; `smtpmail-via-smtp’. In the future, this function might be changed to be a
|
|
||||||
;; valid value for `send-mail-function’
|
|
||||||
|
|
||||||
;; All this functionality is provided under "Mail related customizations". The
|
;; All this functionality is provided under "Mail related customizations". The
|
||||||
;; other headlines provide the aforementioned utility functions.
|
;; other headlines provide the aforementioned utility functions.
|
||||||
|
@ -41,6 +39,8 @@
|
||||||
(require 'epg)
|
(require 'epg)
|
||||||
(require 'mml-sec)
|
(require 'mml-sec)
|
||||||
(require 'gnus)
|
(require 'gnus)
|
||||||
|
(require 'smtpmail) ; to have the globals bound below by let
|
||||||
|
(require 'message)
|
||||||
|
|
||||||
|
|
||||||
;; Mail related customizations
|
;; Mail related customizations
|
||||||
|
@ -115,11 +115,9 @@ will also be recognized when sending mail."
|
||||||
(string :tag "SMTP Login Name")))
|
(string :tag "SMTP Login Name")))
|
||||||
:set #'db/mail-accounts--set-value)
|
:set #'db/mail-accounts--set-value)
|
||||||
|
|
||||||
(defun db/set-smtp-server-from-header (orig-fun &rest args)
|
(defun db/smtpmail-send-it ()
|
||||||
"Choose smtp-settings dynamically, based on the From: header
|
"Send prepared message in current buffer.
|
||||||
entry of the current mail."
|
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’."
|
||||||
(require 'mail-extr)
|
|
||||||
(require 'smtpmail) ; to have the globals bound below by let
|
|
||||||
(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"))
|
||||||
|
@ -142,9 +140,9 @@ entry of the current mail."
|
||||||
t
|
t
|
||||||
"Settings %s for sending mail are not complete for account %s."
|
"Settings %s for sending mail are not complete for account %s."
|
||||||
address)
|
address)
|
||||||
(apply orig-fun args)))
|
(message-smtpmail-send-it)))
|
||||||
(if (yes-or-no-p "Sending with default account settings?")
|
(if (yes-or-no-p "Sending with default account settings?")
|
||||||
(apply orig-fun args)
|
(message-smtpmail-send-it)
|
||||||
(message "Sending aborted as requested by user.")))))
|
(message "Sending aborted as requested by user.")))))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user