Gnus Multiple SMTP accounts

Posted on

Tags: gnus email emacs

[EDIT: As tested, and reported to me by a reader, setting message-send-mail-function (as per the manual) is not required anymore as of Emacs 27.0.50. ]

Today, I discovered that instead of running a smarthost MTA which relays depending on the envelope sender, I could use built-in Gnus smtpmail functionality to do this sender-based routing using gnus-posting-styles:

1
2
3
4
5
6
7
8
9
(setq gnus-posting-styles
      `((".*"
	 (address "default@domain.tld")
	 (name "Name of Sender")
	 ("X-Message-SMTP-Method" "smtp smtp.mta1.tld 587 username1"))
	
	("^nnimap[+]work:.*"
	 (address "me@workdomain.tld")
	 ("X-Message-SMTP-Method" "smtp smtp.work.tld 587 workuser"))))

This way, it adds an email header X-Message-SMTP-Method specifying the SMTP method to use, which smtpmail uses to figure out how to relay the particular email. With credentials stored in $HOME/.authinfo.gpg, this integrates pretty well. Now no more local SMTP server. For more information, refer to (info “(message) Mail Variables”)