From 8d4b766597df7798fa1a519a90d540b11d6c6734 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Mon, 28 Aug 2023 12:28:00 +0200 Subject: [PATCH] Simplify multi SMTP setup using 'message-server-alist' --- .emacs.d/lisp/esy-comm.el | 39 +++++++-------------------------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/.emacs.d/lisp/esy-comm.el b/.emacs.d/lisp/esy-comm.el index 47a35b3..49e17fc 100644 --- a/.emacs.d/lisp/esy-comm.el +++ b/.emacs.d/lisp/esy-comm.el @@ -25,7 +25,6 @@ ;;; Code: (require 'esy-o365) -(require 'savehist) (defvar esy-comm-accounts '(("me" @@ -43,36 +42,16 @@ "%2{%~(form (replace-regexp-in-string \" via .*\" \"\" (gnus-summary-from-or-to-or-newsgroups gnus-tmp-header gnus-tmp-from)))@%} " "%3{(%&user-date;, %k)%}:%* %s\n")) -(defun esy-comm--mail-from () - (without-restriction - (message-narrow-to-headers) - (when-let ((from (mail-fetch-field "from"))) - (cadr (mail-extract-address-components from))))) - -(defun esy-comm-send-message () - (require 'smtpmail) - (if-let ((from (esy-comm--mail-from)) - (server (alist-get from - (mapcar (pcase-lambda - (`(,_ ,car ,_ ,cdr . ,_)) - (cons car cdr)) - esy-comm-accounts) - nil nil #'string=))) - (let ((smtpmail-smtp-user from) - (smtpmail-smtp-server server) - (smtpmail-smtp-service 587) - (smtpmail-stream-type 'starttls) - (smtpmail-servers-requiring-authorization ".*")) - (smtpmail-send-it)) - (user-error "Unrecognized FROM address, not sending"))) - (setq - ;; sendmail.el - send-mail-function #'esy-comm-send-message - ;; Message - message-send-mail-function #'esy-comm-send-message message-alternative-emails (regexp-opt (mapcar #'cadr esy-comm-accounts)) + message-dont-reply-to-names message-alternative-emails + message-elide-ellipsis "\n[...%l lines elided...]\n" + message-server-alist (mapcar (pcase-lambda + (`(,_ ,cond ,_ ,server . ,_)) + (cons cond + (format "smtp %s 587" server))) + esy-comm-accounts) ;; Gnus gnus-expert-user t @@ -131,9 +110,5 @@ (with-eval-after-load 'message (add-hook 'message-send-hook 'ispell-message)) -(with-eval-after-load 'savehist - (add-to-list 'savehist-additional-variables - 'esy-o365-token-refresh-last-time)) - (provide 'esy-comm) ;;; esy-comm.el ends here -- 2.39.2