]> git.eshelyaron.com Git - dotfiles.git/commitdiff
Update Gnus mail configuration
authorEshel Yaron <me@eshelyaron.com>
Sat, 26 Aug 2023 12:05:13 +0000 (14:05 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sat, 26 Aug 2023 12:05:13 +0000 (14:05 +0200)
.emacs.d/init.el

index 106f2f0453b58f60c7da2f946dcf86e73e25c58c..797dcf552334b41d2a9ed417045c49e85072f032 100644 (file)
 (elpaca rainbow-delimiters)
 (elpaca rainbow-mode)
 (elpaca rg)
-(elpaca smtpmail-multi)
 (elpaca sqlformat)
 (elpaca (sweeprolog
          :repo "~/checkouts/sweep/"
  vc-follow-symlinks t
  ;; jump from .c to .h files with find-sibling-file
  find-sibling-rules '(("\\([^/]+\\)\\.c\\'" "\\1.h"))
- ;; configure multiple SMTP accounts
- smtpmail-multi-accounts '((esy . ("eshelshay.yaron@gmail.com"
-                                   "smtp.gmail.com" 587
-                                   "eshelshay.yaron@gmail.com"
-                                   starttls nil nil nil))
-                           (swp . ("eshel@swi-prolog.org"
-                                   "mail.swi-prolog.com" 587
-                                   "eshel@swi-prolog.org"
-                                   starttls nil nil nil))
-                           (me  . ("me@eshelyaron.com"
-                                   "mail.eshelyaron.com"
-                                   587
-                                   "me@eshelyaron.com"
-                                   starttls nil nil nil))
-                           (uva  . ("eshel.yaron@student.uva.nl"
-                                   "smtp.office365.com"
-                                   587
-                                   "eshel.yaron@student.uva.nl"
-                                   starttls nil nil nil)))
- ;; associate email addresses with SMTP accounts
- smtpmail-multi-associations '(("eshelshay\.yaron@gmail\.com"   esy)
-                               ("eshel@swi-prolog\.org"         swp)
-                               ("me@eshelyaron\.com"             me)
-                               ("eshel\.yaron@student\.uva\.nl" uva))
+ message-alternative-emails (regexp-opt '("eshelshay.yaron@gmail.com"
+                                          "me@eshelyaron.com"
+                                          "eshel@swi-prolog.org"
+                                          "eshel.yaron@student.uva.nl"))
  ;; set function for sending email
- send-mail-function #'smtpmail-multi-send-it
- message-send-mail-function #'smtpmail-multi-send-it
+ send-mail-function #'esy/smtp-send-it
+ message-send-mail-function #'esy/smtp-send-it
  ;; set email user agent
  mail-user-agent 'gnus-user-agent
  read-mail-command 'gnus
                                          (nnimap-address "outlook.office365.com")
                                          (nnimap-server-port "imaps")
                                          (nnimap-stream ssl)
-                                         (nnimap-authenticator xoauth2))
-                                 )
+                                         (nnimap-authenticator xoauth2)))
  ;; simpler message
  gnus-no-groups-message "No new articles"
  ;; don't close other windows when opening Gnus
@@ -1173,6 +1151,34 @@ as the initial input for completion, and return that directory."
   (gnus-icalendar-org-setup)
   (bbdb-initialize 'gnus 'mail 'message))
 
+
+(defvar esy/smtp-accounts
+  '(("eshelshay.yaron@gmail.com"  . "smtp.gmail.com")
+    ("eshel@swi-prolog.org"       . "mail.swi-prolog.com")
+    ("me@eshelyaron.com"          . "mail.eshelyaron.com")
+    ("eshel.yaron@student.uva.nl" . "smtp.office365.com")))
+
+(defun esy/mail-from ()
+  (without-restriction
+    (message-narrow-to-headers)
+    (when-let ((from (mail-fetch-field "from")))
+      (cadr (mail-extract-address-components from)))))
+
+(defun esy/smtp-send-it ()
+  (require 'smtpmail)
+  (if-let ((from (esy/mail-from))
+           (server (alist-get from esy/smtp-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")))
+
+(with-eval-after-load 'message
+  (add-hook 'message-send-hook 'ispell-message))
+
 ;;; Configure `dired'
 
 (with-eval-after-load 'dired