From: Andrew G Cohen Date: Wed, 3 May 2023 03:37:45 +0000 (+0800) Subject: Allow X-Message-SMTP-Method to include more MTAs X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=f261226d9be4630572df322b2c4f48713c9c2fce;p=emacs.git 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. --- diff --git a/doc/misc/message.texi b/doc/misc/message.texi index c3ad8dd6942..8064af53fc6 100644 --- a/doc/misc/message.texi +++ b/doc/misc/message.texi @@ -1948,11 +1948,9 @@ requires the @acronym{POP}-before-@acronym{SMTP} authentication. @cindex X-Message-SMTP-Method 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 -can use the @samp{X-Message-SMTP-Method} header. These are the -supported values: - -@table @samp -@item smtpmail +can use the @samp{X-Message-SMTP-Method} header to override the +default by using the keyword @samp{smtp} followed by the server +information: @example 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 @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 X-Message-SMTP-Method: sendmail @end example -This will send the message via the locally installed sendmail/exim/etc -installation. +will send the message via the locally installed sendmail program. The +recognized values of @samp{mailer} are sendmail, qmail, mh, and +mailclient. -@end table @item message-mh-deletable-headers @vindex message-mh-deletable-headers diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el index b35424a8581..45cc21701b3 100644 --- a/lisp/gnus/message.el +++ b/lisp/gnus/message.el @@ -5009,30 +5009,34 @@ Each line should be no more than 79 characters long." "Send the current buffer to `message-send-mail-function'. Or, if there's a header that specifies a different method, use 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) - (funcall message-send-mail-function) + (funcall message-send-mail-function) (message-remove-header "X-Message-SMTP-Method") (setq method (split-string method)) + (setq send-function + (symbol-function + (intern-soft (format "message-send-mail-with-%s" (car method))))) (cond - ((equal (car method) "sendmail") - (message-send-mail-with-sendmail)) ((equal (car method) "smtp") - (require 'smtpmail) - (let* ((smtpmail-store-queue-variables t) + (require 'smtpmail) + (let* ((smtpmail-store-queue-variables t) (smtpmail-smtp-server (nth 1 method)) - (service (nth 2 method)) - (port (string-to-number service)) - ;; If we're talking to the TLS SMTP port, then force a - ;; TLS connection. - (smtpmail-stream-type (if (= port 465) - 'tls - smtpmail-stream-type)) - (smtpmail-smtp-service (if (> port 0) port service)) - (smtpmail-smtp-user (or (nth 3 method) smtpmail-smtp-user))) - (message-smtpmail-send-it))) + (service (nth 2 method)) + (port (string-to-number service)) + ;; If we're talking to the TLS SMTP port, then force a + ;; TLS connection. + (smtpmail-stream-type (if (= port 465) + 'tls + smtpmail-stream-type)) + (smtpmail-smtp-service (if (> port 0) port service)) + (smtpmail-smtp-user (or (nth 3 method) smtpmail-smtp-user))) + (message-smtpmail-send-it))) + (send-function + (funcall send-function)) (t - (error "Unknown method %s" method)))))) + (error "Unknown mail method %s" method)))))) (defun message-send-mail-with-sendmail () "Send off the prepared buffer with sendmail."