From cce817c63fe2b54adbad6c00ce883e5ed4e3f7cf Mon Sep 17 00:00:00 2001 From: Oscar Najera Date: Tue, 19 Sep 2023 17:44:15 +0200 Subject: new smtp server selector Plays along with auth source and I don't keep that much information on the config. --- config/doom/config.org | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'config') 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 " - "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 -- cgit v1.2.3