Sendmail relay to non standard smtp port via mailertable

The Sendmail mailertable is used to route email. By default, the Sendmail smtp delivery agents used to relay mail will connect to other host through the standard SMTP port 25. From the Sendmail FAQ How do I send using an alternate port, we know that it’s possible to relay to other port by define the **MAILER_ARGS, however, that will work for all relay. What if we want to relay to one host running SMTP on port 26, and another host running SMTP on port 8825? We can implement this by adding other mailer.

Edit /etc/mail/sendmail.cf, Add the following two mailer definition to the enf of the file

#########esmtp on port 26####
Mesmtp26,               P=[IPC], F=mDFMuXa, S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP, E=\r\n, L=990,
                T=DNS/RFC822/SMTP,
                A=TCP $h 26
#########esmtp on port 8825####
Mesmtp8825,             P=[IPC], F=mDFMuXa, S=EnvFromSMTP/HdrFromSMTP, R=EnvToSMTP, E=\r\n, L=990,
                T=DNS/RFC822/SMTP,
                A=TCP $h 8825

Here we defined two mailer called esmtp26 and esmtp8825 . What we do here is to copy the definition of the esmtp mailer, give it a new name, and change its argument( the A=TCP .. line, the port number is defined after $h ) to use whichever port we want.

Now, in mailertable, we can configure email route to use the two mailers like this.

#relay all mail for asia.example.com to srv1.example.com on port 26
asia.example.com    esmtp26:[srv1.example.com]
#relay all mail for euro.example.com to srv2.example.com on port 8825
euro.example.com    esmtp8825:[srv2.example.com]
#relay mail for example.org to srv3.example.com on standard port 25
example.org    smtp:[srv3.example.com]
This entry was posted in Email, System Administration and tagged , . Bookmark the permalink.

Leave a Reply