summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-12-24 14:30:42 +0800
committerJSDurand <mmemmew@gmail.com>2021-12-24 14:30:42 +0800
commit4903e67192bed09685963452dce3c77f208faa79 (patch)
tree0606159a4ab48a269fc9e5efa6959f3254d325ad
parentf6bb4ec55c39478163c8604d7cf6488d51de172c (diff)
Use multiple SMTP servers now
* gnus-conf.el (gnus-secondary-select-methods): Add mailboxes corresponding to the new server. (smtpmail-smtp-user): Just a random change. (durand-smtp-servers): The association list of my servers. (durand-set-smtp-server-message-send-and-exit): Set the server automagically. (message-mode-map): Bind C-c C-c to the magic command. * mail.el (mu4e-get-mail-command): Specify exactly what channels should be updated by a call to mbsync, just to be more precise and pedantic.
-rw-r--r--gnus-conf.el78
-rw-r--r--mail.el7
2 files changed, 82 insertions, 3 deletions
diff --git a/gnus-conf.el b/gnus-conf.el
index 9546063..7d0fa23 100644
--- a/gnus-conf.el
+++ b/gnus-conf.el
@@ -7,7 +7,8 @@
(setq gnus-select-method '(nnnil ""))
(setq gnus-secondary-select-methods
'(;; (nntp "news.gmane.io")
- (nnmaildir "private" (directory "~/.nnmaildir"))
+ (nnmaildir "gmail" (directory "~/.nnmaildir/gmail"))
+ (nnmaildir "durand" (directory "~/.nnmaildir/mymail"))
;; (nnmaildir "sent" (directory "~/.nnmaildir"))
;; (nnimap "LocalMail"
;; (nnimap-address "localhost")
@@ -91,7 +92,7 @@
(setq gnus-ignored-from-addresses "mmemmew@gmail.com")
(setq send-mail-function #'smtpmail-send-it)
-(setq smtpmail-smtp-user "mmemmew@gmail.com")
+(setq smtpmail-smtp-user "durand@jsdurand.xyz")
(setq gnus-user-agent '(emacs gnus config))
@@ -129,6 +130,76 @@
(setq gnus-gcc-mark-as-read t)
+;;; Multiple SMTP servers
+
+(defvar durand-smtp-servers nil
+ "The list of SMTP servers that I use.
+Each server is a list of the form:
+
+(SENDER SERVER PORT USERNAME)
+
+SENDER is a string to match the \"FROM\" field of EMails.
+
+SERVER is the server to use.
+
+PORT is the port to use.
+
+USERNAME is used to look up passwords in ~/.authinfo.gpg.")
+
+(setq durand-smtp-servers
+ (list
+ (list "durand@jsdurand.xyz"
+ "mail.jsdurand.xyz"
+ 587
+ "durand@jsdurand.xyz")
+ (list "mmemmew@gmail.com"
+ "smtp.gmail.com"
+ 587
+ "mmemmew@gmail.com")))
+
+(defun durand-set-smtp-server-message-send-and-exit ()
+ "Set SMTP server according to `durand-smtp-servers' and send mail."
+ (interactive)
+ ;; We always determine this automatically.
+ (message-remove-header "X-Message-SMTP-Method")
+ (let* ((sender (message-fetch-field "From"))
+ (server-form (alist-get sender durand-smtp-servers
+ nil nil #'string-match-p)))
+ (cond
+ ((and (null server-form)
+ (y-or-n-p
+ "Do you want to change the default SMTP server?"))
+ (setq server-form
+ (alist-get (completing-read "Choose a server: "
+ durand-smtp-servers
+ nil t)
+ durand-smtp-servers
+ nil nil #'string=))))
+ ;; if there is a server to use, we change to it
+ (cond
+ (server-form
+ (message-add-header
+ (format
+ "X-Message-SMTP-Method: smtp %s %d %s"
+ (car server-form) (cadr server-form) (caddr server-form)))))
+ ;; send the message if possible
+ (let ((xmess (message-fetch-field "X-Message-SMTP-Method")))
+ (cond
+ (xmess
+ (message
+ (format "Sending message using '%s' with config '%s'"
+ sender xmess))
+ (message-send-and-exit))
+ (user-error
+ (concat
+ "Could not find SMTP Server for this Sender address: %s."
+ "You might want to correct it or add it to "
+ "the list 'durand-smtp-servers'.")
+ sender)))))
+
+(define-key message-mode-map (vector 3 3)
+ #'durand-set-smtp-server-message-send-and-exit)
+
;;; Call me an expert.
(setq gnus-expert-user t)
@@ -281,3 +352,6 @@
;; Don't query me each time
(setq sc-confirm-always-p nil)
+
+(provide 'gnus-conf)
+;;; gnus-conf.el ends here
diff --git a/mail.el b/mail.el
index 308e078..b8f7aa2 100644
--- a/mail.el
+++ b/mail.el
@@ -12,7 +12,9 @@
(setq mu4e-view-use-gnus t)
(setq mu4e-confirm-quit nil)
- (setq mu4e-get-mail-command "mbsync -a") ; mbsync works a lot better!
+ ;; mbsync works a lot better!
+ (setq mu4e-get-mail-command
+ "mbsync mymail-inbox mymail-sent gmail-inbox gmail-sent")
(setq mu4e-change-filenames-when-moving t)
(setq mu4e-view-show-addresses t) ; show full addresses!
(setq mu4e-view-show-images t)
@@ -107,6 +109,9 @@
(smtpmail-smtp-server . "smtp.gmail.com")
(smtpmail-smtp-service . 587))))))
+;; (setq smtpmail-debug-info t)
+;; (setq smtpmail-debug-verb t)
+
;;; message mode
(require 'message)