Page: [root]/howto/multiple-smarthosts | src | faq | css

How to send email using two smarthosts, easy and reliable way

Recently I needed to use two email addresses, both for sending and receiving mail. I could use mutt for everything, but I prefer separating receiving mail, reading it and sending into three separate programs. So, I tried to configure exim4, which I have already been using for sending mail via one smarthost, for that, but it's bloated piece of crap, the only sane way of interacting with which is debian configuration, which does not support multiple smarthosts.

So I tried several MTAs until I found opensmtpd. It still uses some kind of homebrew config system but it's quite okay. So here's approximately how do you send mail via appropriate smarthost, based on sender address:

# /etc/opensmtpd.conf
listen on localhost

table aliases file:/etc/aliases
table sender1 { myfirstaddress@host1 }
table sender2 { mysecondaddress@host2 }
table secrets db:/etc/mail/secrets.db

# local mta functionality
accept for local alias <aliases> deliver to mbox

accept for any sender <sender1> relay via tls+auth://mail1@host:587 auth <secrets>
accept for any sender <sender2> relay via tls+auth://mail2@host2:587 auth <secrets>

To fill /etc/mail/secrets.db with your passwords, create /etc/mail/secrets with something like:

mail1 user1:password1
mail2 user2:password2

and run makemap /etc/mail/secrets.

"myfirstaddress@host1" and "mysecondaddress@host2" are your emails, "tls+auth://mailX@hostX:587" are your SMTP connection details (see man smtpd.conf for details), userX:passwordX are your SMTP credentials.

Powered by bitcheese wiki engine