]> git.eshelyaron.com Git - dotfiles.git/commitdiff
Simplify multi SMTP setup using 'message-server-alist'
authorEshel Yaron <me@eshelyaron.com>
Mon, 28 Aug 2023 10:28:00 +0000 (12:28 +0200)
committerEshel Yaron <me@eshelyaron.com>
Mon, 28 Aug 2023 10:28:00 +0000 (12:28 +0200)
.emacs.d/lisp/esy-comm.el

index 47a35b347c1ee5c37615daa021869acfd8561a86..49e17fccfd6a79048bcd334d1500c34165081603 100644 (file)
@@ -25,7 +25,6 @@
 ;;; Code:
 
 (require 'esy-o365)
-(require 'savehist)
 
 (defvar esy-comm-accounts
   '(("me"
           "%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
 (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