Emacs and Multiple SMTP servers

0

1

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?

pmr

Posted 2012-06-14T22:39:11.680

Reputation: 131

Answers

2

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)
      (save-excursion
    (let* ((from
        (save-restriction
          (message-narrow-to-headers)
          (message-fetch-field "from")))
           (account
        (cond
         ;; 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
      '(("nnimap\\+EXAMPLE2:INBOX"
     (address "mitchelh@example2.com"))))

mgalgs

Posted 2012-06-14T22:39:11.680

Reputation: 1 762

I arrived at something incredibly similar a few days ago. – pmr – 2012-08-29T23:47:00.400