diff --git a/.emacs.d/lisp/init-smtpmail.el b/.emacs.d/lisp/init-smtpmail.el index 6162e873..38de080c 100644 --- a/.emacs.d/lisp/init-smtpmail.el +++ b/.emacs.d/lisp/init-smtpmail.el @@ -5,12 +5,20 @@ smtpmail-stream-type 'starttls smtpmail-smtp-service 587) -;; This is only useful to distinguish between similar entries in .authinfo. -;; (setq smtpmail-smtp-user user-mail-address) - ;; REVIEW: If we don't set `user-mail-address', `mail-host-address' or ;; `message-user-fqdn', `message-make-fqdn' will put ;; "i-did-not-set--mail-host-address--so-tickle-me" in the In-Reply-To header. (setq user-mail-address "mail@ambrevar.xyz") +;; This is only useful to distinguish between similar entries in .authinfo / password-store. +(defun ambrevar/set-smtp-user () + "Set `smtpmail-smtp-user' to the value in the \"From\" field." + (let ((header-value (message-fetch-field "From"))) + (and + header-value + (setq smtpmail-smtp-user + (substring-no-properties + (cadr (mail-extract-address-components header-value))))))) +(add-hook 'message-send-hook #'ambrevar/set-smtp-user) + (provide 'init-smtpmail)