From: Philip Kaludercic <philipk@posteo.net>
To: 52205@debbugs.gnu.org
Subject: bug#52205: Allow configuring multiple mail accounts for smtpmail.el
Date: Tue, 30 Nov 2021 19:45:10 +0000 [thread overview]
Message-ID: <87fsrdmnqx.fsf@posteo.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 1137 bytes --]
Tags: patch
Tags: patch
Hi,
the below patch should allow for multiple mail accounts being configured
for smtpmail.el, without having to use tricks like
X-Message-SMTP-Method, that only work when the MUA also inserts them at
the right time.
This is an initial patch, and everything seems to work on my end. I had
a little issue with the indentation, because Emacs re-indented
everything at first, but I didn't want to send a patch consisting of
mainly unrelated whitespace changes.
In GNU Emacs 28.0.60 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.24, cairo version 1.16.0)
of 2021-11-30 built on viero
Repository revision: c4daff9cf844ec85930bdcd2064787c92c260861
Repository branch: emacs-28
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
Configured using:
'configure CC=gcc
PKG_CONFIG_PATH=/gnu/store/sfqc239vzd9d1hxmnvav385x1nl9zx5d-profile/lib/pkgconfig:/gnu/store/sfqc239vzd9d1hxmnvav385x1nl9zx5d-profile/share/pkgconfig:/home/philip/.guix-profile/lib/pkgconfig:/home/philip/.guix-profile/share/pkgconfig:/home/philip/.guix-profile/lib/pkgconfig:/home/philip/.guix-profile/share/pkgconfig'
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-configuring-multiple-mail-accounts-for-smtpmai.patch --]
[-- Type: text/patch, Size: 3144 bytes --]
From d4685683a265d53b28471e68c68ec8c6411e4aa7 Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
Date: Tue, 30 Nov 2021 20:00:58 +0100
Subject: [PATCH] Allow configuring multiple mail accounts for smtpmail.el
* lisp/mail/smtpmail.el (smtpmail-smtp-server-alist): New option to
configure what server to use for what outgoing address.
---
lisp/mail/smtpmail.el | 31 ++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)
diff --git a/lisp/mail/smtpmail.el b/lisp/mail/smtpmail.el
index bd8aa611e9..95e7abdeae 100644
--- a/lisp/mail/smtpmail.el
+++ b/lisp/mail/smtpmail.el
@@ -78,6 +78,19 @@ smtpmail-smtp-server
"The name of the host running SMTP server."
:type '(choice (const nil) string))
+(defcustom smtpmail-smtp-server-alist '()
+ "Alist of SMTP servers for different addresses."
+ :type '(alist :key-type
+ (string :tag "Sender")
+ :value-type
+ (list (string :tag "SMTP Server")
+ (natnum :tag "Service")
+ (choice :tag "Stream type"
+ (const :tag "Possibly upgrade to STARTTLS" nil)
+ (const :tag "Always use STARTTLS" starttls)
+ (const :tag "Never use STARTTLS" plain)
+ (const :tag "Use TLS/SSL" ssl)))))
+
(defcustom smtpmail-smtp-service 25
"SMTP service port number.
The default value would be \"smtp\" or 25."
@@ -706,13 +719,9 @@ smtpmail-user-mail-address
(defun smtpmail-via-smtp (recipient smtpmail-text-buffer
&optional ask-for-password
send-attempts)
- (unless smtpmail-smtp-server
+ (unless (or smtpmail-smtp-server smtpmail-smtp-server-alist)
(smtpmail-query-smtp-server))
- (let ((process nil)
- (send-attempts (or send-attempts 1))
- (host (or smtpmail-smtp-server
- (error "`smtpmail-smtp-server' not defined")))
- (port smtpmail-smtp-service)
+ (let* ((process nil)
;; `smtpmail-mail-address' should be set to the appropriate
;; buffer-local value by the caller, but in case not:
(envelope-from
@@ -727,6 +736,14 @@ smtpmail-via-smtp
(and from
(cadr (mail-extract-address-components from))))
(smtpmail-user-mail-address))))
+ (send-attempts (or send-attempts 1))
+ (server (alist-get envelope-from smtpmail-smtp-server-alist
+ (list smtpmail-smtp-server)
+ nil #'string=))
+ (host (or (car server)
+ (error "No known SMTP Server for %S" envelope-from)))
+ (port (or (cadr server)
+ smtpmail-smtp-service))
process-buffer
result
auth-mechanisms
@@ -757,7 +774,7 @@ smtpmail-via-smtp
(setq result
(open-network-stream
"smtpmail" process-buffer host port
- :type smtpmail-stream-type
+ :type (or (caddr server) smtpmail-stream-type)
:return-list t
:warn-unless-encrypted ask-for-password
:capability-command (format "EHLO %s\r\n" (smtpmail-fqdn))
--
2.34.0
[-- Attachment #3: Type: text/plain, Size: 24 bytes --]
--
Philip Kaludercic
next reply other threads:[~2021-11-30 19:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-30 19:45 Philip Kaludercic [this message]
2021-12-01 4:08 ` bug#52205: Allow configuring multiple mail accounts for smtpmail.el Lars Ingebrigtsen
2021-12-01 9:01 ` Philip Kaludercic
2021-12-01 19:21 ` Lars Ingebrigtsen
2021-12-01 20:15 ` Philip Kaludercic
2021-12-01 20:24 ` Lars Ingebrigtsen
2021-12-02 23:06 ` Philip Kaludercic
2021-12-03 16:17 ` Lars Ingebrigtsen
2021-12-04 9:12 ` Philip Kaludercic
2021-12-04 19:01 ` Lars Ingebrigtsen
2021-12-13 19:20 ` Philip Kaludercic
2021-12-14 13:41 ` Lars Ingebrigtsen
2021-12-18 13:45 ` Philip Kaludercic
2021-12-19 10:57 ` Lars Ingebrigtsen
2021-12-19 21:59 ` Philip Kaludercic
2021-12-22 12:20 ` Lars Ingebrigtsen
2022-09-09 17:53 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fsrdmnqx.fsf@posteo.net \
--to=philipk@posteo.net \
--cc=52205@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).