Allow X-Message-SMTP-Method to include more MTAs

* lisp/gnus/message.el (message-multi-smtp-send-mail): Allow the
X-Message-SMTP-Method header to override the default mailer with not
only smtp and sendmail but other MTAs as well.
* doc/misc/message.texi: Document changes to the usage of
X-Message-SMTP-Method.
This commit is contained in:
Andrew G Cohen 2023-05-03 11:37:45 +08:00
parent 8d1332d135
commit f261226d9b
2 changed files with 31 additions and 26 deletions

View file

@ -1948,11 +1948,9 @@ requires the @acronym{POP}-before-@acronym{SMTP} authentication.
@cindex X-Message-SMTP-Method @cindex X-Message-SMTP-Method
If you have a complex @acronym{SMTP} setup, and want some messages to If you have a complex @acronym{SMTP} setup, and want some messages to
go via one mail server, and other messages to go through another, you go via one mail server, and other messages to go through another, you
can use the @samp{X-Message-SMTP-Method} header. These are the can use the @samp{X-Message-SMTP-Method} header to override the
supported values: default by using the keyword @samp{smtp} followed by the server
information:
@table @samp
@item smtpmail
@example @example
X-Message-SMTP-Method: smtp smtp.fsf.org 587 X-Message-SMTP-Method: smtp smtp.fsf.org 587
@ -1968,16 +1966,19 @@ This is the same as the above, but uses @samp{other-user} as the user
name when authenticating. This is handy if you have several name when authenticating. This is handy if you have several
@acronym{SMTP} accounts on the same server. @acronym{SMTP} accounts on the same server.
@item sendmail This header may also be used to specify an alternative MTA by using a
@samp{mailer} keyword, where @samp{mailer} is the name of an MTA with
a corresponding @code{message-send-mail-with-'mailer'} function. For
example:
@example @example
X-Message-SMTP-Method: sendmail X-Message-SMTP-Method: sendmail
@end example @end example
This will send the message via the locally installed sendmail/exim/etc will send the message via the locally installed sendmail program. The
installation. recognized values of @samp{mailer} are sendmail, qmail, mh, and
mailclient.
@end table
@item message-mh-deletable-headers @item message-mh-deletable-headers
@vindex message-mh-deletable-headers @vindex message-mh-deletable-headers

View file

@ -5009,30 +5009,34 @@ Each line should be no more than 79 characters long."
"Send the current buffer to `message-send-mail-function'. "Send the current buffer to `message-send-mail-function'.
Or, if there's a header that specifies a different method, use Or, if there's a header that specifies a different method, use
that instead." that instead."
(let ((method (message-field-value "X-Message-SMTP-Method"))) (let ((method (message-field-value "X-Message-SMTP-Method"))
send-function)
(if (not method) (if (not method)
(funcall message-send-mail-function) (funcall message-send-mail-function)
(message-remove-header "X-Message-SMTP-Method") (message-remove-header "X-Message-SMTP-Method")
(setq method (split-string method)) (setq method (split-string method))
(setq send-function
(symbol-function
(intern-soft (format "message-send-mail-with-%s" (car method)))))
(cond (cond
((equal (car method) "sendmail")
(message-send-mail-with-sendmail))
((equal (car method) "smtp") ((equal (car method) "smtp")
(require 'smtpmail) (require 'smtpmail)
(let* ((smtpmail-store-queue-variables t) (let* ((smtpmail-store-queue-variables t)
(smtpmail-smtp-server (nth 1 method)) (smtpmail-smtp-server (nth 1 method))
(service (nth 2 method)) (service (nth 2 method))
(port (string-to-number service)) (port (string-to-number service))
;; If we're talking to the TLS SMTP port, then force a ;; If we're talking to the TLS SMTP port, then force a
;; TLS connection. ;; TLS connection.
(smtpmail-stream-type (if (= port 465) (smtpmail-stream-type (if (= port 465)
'tls 'tls
smtpmail-stream-type)) smtpmail-stream-type))
(smtpmail-smtp-service (if (> port 0) port service)) (smtpmail-smtp-service (if (> port 0) port service))
(smtpmail-smtp-user (or (nth 3 method) smtpmail-smtp-user))) (smtpmail-smtp-user (or (nth 3 method) smtpmail-smtp-user)))
(message-smtpmail-send-it))) (message-smtpmail-send-it)))
(send-function
(funcall send-function))
(t (t
(error "Unknown method %s" method)))))) (error "Unknown mail method %s" method))))))
(defun message-send-mail-with-sendmail () (defun message-send-mail-with-sendmail ()
"Send off the prepared buffer with sendmail." "Send off the prepared buffer with sendmail."