There used to be a bunch of hacks for using multiple SMTP servers with Gnus that mostly entailed to add a special mail header depending on the current group and parsing this information out with a custom send-mail function.

Since Emacs 24 most available work-arounds broke, while sendmail is now much easier to use and setup with a single server.

What is the best way to have multiple SMTP servers with Gnus and use the one belonging to the group I'm currently reading in Emacs 24?


I'm using msmtp and this setup and some gnus-posting-styles successfully on Emacs 24.1.1.

(defun cg-feed-msmtp ()
  (if (message-mail-p)
    (let* ((from
          (message-fetch-field "from")))
         ;; I use email address as account label in ~/.msmtprc
         ((string-match "mitchelh@example1.com" from) "example1")
         ;; Add more string-match lines for your email accounts
         ((string-match "mitchelh@example2.com" from) "example2"))))
      (setq message-sendmail-extra-arguments (list '"-a" account))))))

(setq message-sendmail-envelope-from 'header)
(add-hook 'message-send-mail-hook 'cg-feed-msmtp)

(setq gnus-posting-styles
     (address "mitchelh@example2.com"))))
| improve this answer | |
  • I arrived at something incredibly similar a few days ago. – pmr Aug 29 '12 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.