localhost as a smart SMTP relay

You have a production server which is not configured to relay mails externally, but there is a application running in that server which mails its log to the given email address regarding its status and incase of any service failures. since the sendmail runs locally on localhost.localdomain name it tries to forward the mail with root@localhost.localdomain to the remote smtp server, which would get rejected because of the reason that localhost.localdomain resolves to Invalid IP. So in order to overcome that we have to rewrite the from address of root@localhost.localdomain to user@example.com. so that the other smtp server relays the mail from user@example.com to the admin@example.com or whatever address you want to send the service status mail to.


Check for installed sendmail packages –

apt-get install sendmail-base sendmail-bin sendmail-cf sendmail


First add the remote server ip address and its domain name to the /etc/hosts

vi /etc/hosts smtp.example.com

You don’t have to do the above step if your local dns can resolve the domain name to the ip address of the smtp server which is configured to relay mail.


Edit the Sendmail configuration file for forwarding mails

vi /etc/mail/sendmail.mc

EXPOSED_USER(root uucp)dnl # users exempt from masquerading
dnl # Masquerading options
FEATURE(`nullclient’, smtpservername)dnl



run the ‘make’ command on /etc/mail directory then reload the sendmail server
/etc/init.d/sendmail reload

Finally, test your settings –
telnet localhost 25
Connected to localhost.
Escape character is ‘^]’.
220 clinet1.example.com ESMTP Sendmail 8.14.3/8.14.3/Debian-5; Tue, 2 Feb 2010 13:41:34 +0600; (No UCE/UBE) logging access from: localhost(OK)-localhost []
helo smtp
250 client1.example.com Hello localhost [], pleased to meet you
mail from:root@client1.example.com
250 2.1.0 root@client1.example.com… Sender ok
rcpt to:tarique@yahoo.com
250 2.1.5 tarique@yahoo.com… Recipient ok
354 Enter mail, end with “.” on a line by itself
hello from example1
250 2.0.0 o127fY1s008960 Message accepted for delivery
[type quit to exit].


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: