aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2023-09-19 17:44:15 +0200
committerOscar Najera <hi@oscarnajera.com>2023-09-19 17:45:09 +0200
commitcce817c63fe2b54adbad6c00ce883e5ed4e3f7cf (patch)
tree300aed72aae926aac62e6b54640724108534f45d
parent33777a17e8d8b7f43741c0bcf0330ded3d02a282 (diff)
downloaddotfiles-cce817c63fe2b54adbad6c00ce883e5ed4e3f7cf.tar.gz
dotfiles-cce817c63fe2b54adbad6c00ce883e5ed4e3f7cf.tar.bz2
dotfiles-cce817c63fe2b54adbad6c00ce883e5ed4e3f7cf.zip
new smtp server selector
Plays along with auth source and I don't keep that much information on the config.
-rw-r--r--config/doom/config.org36
1 files changed, 21 insertions, 15 deletions
diff --git a/config/doom/config.org b/config/doom/config.org
index 566a3ac..75ebc18 100644
--- a/config/doom/config.org
+++ b/config/doom/config.org
@@ -413,21 +413,27 @@ this new window.
smtpmail-local-domain "oscarnajera.com")
(defun set-smtp-server ()
- (let* ((default-smtp-conf '("mail.oscarnajera.com" 587 starttls "hi"))
- (smtp-from-server-alist
- '(("Oscar Najera <najera.oscar@gmail.com>"
- "smtp.googlemail.com" 587 starttls "najera.oscar")))
- (smtp-conf (alist-get (save-restriction
- (message-narrow-to-headers)
- (message-fetch-field "from"))
- smtp-from-server-alist default-smtp-conf
- nil #'string=)))
- (-let [(server port protocol user) smtp-conf]
- (setq smtpmail-smtp-server server
- smtpmail-smtp-service port
- smtpmail-stream-type protocol
- smtpmail-smtp-user user)
- (message "SMTP server changed to %s in port %s by %s" server port protocol))))
+ (-let* (((user host)
+ (thread-first
+ (message-field-value "from" )
+ (mail-extract-address-components)
+ (cadr)
+ (string-split "@")))
+ (smtp-servers '("oscarnajera.com" "mail.oscarnajera.com"
+ "gmail.com" "smtp.googlemail.com"
+ "byteplant.com" "smtp.byteplant.com"))
+ ((&plist :host :user :port :secret)
+ (car
+ (auth-source-search :host
+ (or (plist-get smtp-servers host #'string=)
+ "mail.oscarnajera.com")
+ :user user
+ :max 1))))
+ (setq smtpmail-smtp-server host
+ smtpmail-smtp-service (string-to-number port)
+ smtpmail-stream-type 'starttls
+ smtpmail-smtp-user user)
+ (message "SMTP server changed to %s %s %s" host port user)))
(add-hook 'message-send-mail-hook 'set-smtp-server))
#+end_src