From f05e86562e1aa041e267e66ed7fc5ee7fc20e2d0 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Sat, 26 Aug 2023 14:05:13 +0200 Subject: [PATCH] Update Gnus mail configuration --- .emacs.d/init.el | 64 ++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index 106f2f0..797dcf5 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -183,7 +183,6 @@ (elpaca rainbow-delimiters) (elpaca rainbow-mode) (elpaca rg) -(elpaca smtpmail-multi) (elpaca sqlformat) (elpaca (sweeprolog :repo "~/checkouts/sweep/" @@ -394,33 +393,13 @@ 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 @@ -457,8 +436,7 @@ (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 -- 2.39.2