Example Scenario: 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 firstname.lastname@example.org 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 email@example.com to firstname.lastname@example.org. so that the other smtp server relays the mail from email@example.com to the firstname.lastname@example.org or whatever address you want to send the service status mail to.
NOTE: Specific parts of this tutorial applies only to Redhat Based Systems, but in general the procedure applies to all
Install the Rpmsroot@domain# yum install sendmail sendmail-cf
It should install them in your linux system.
Once installed you have to make sure the server is started and starts automatically on reboot.
root@domain# chkconfig sendmail on
root@domain# service sendmail start
Now the server is up and running.
First add the remote server ip address and its domain name to the /etc/hosts
You dont 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
Forwarding mails to smarthost
Then save the file.
For rewriting the from address of the mails create genericstable file.
#vi /etc/mail/genericstableIn the Generics table file enter the following lines:
root email@example.com mohan firstname.lastname@example.org
The above lines mean that if any mails sent by root will be masqueraded and appear to come from as email@example.com instead of firstname.lastname@example.org and if any mail sent by the user mohan will appear to come from email@example.com instead of firstname.lastname@example.org
Then save the file.
Enabling Features in the sendmail configuration file.
#vi /etc/mail/sendmail.mcAdd these lines for enabling features:
FEATURE(masquerade_envelope)dnl FEATURE(`genericstable')dnl GENERICS_DOMAIN(`localhost.localdomain')dnl
#make -C /etc/mailIt should compile all the files under the /etc/mail directory and updates the changes.
After that restart the sendmail service.
root@domain# service sendmail restartThat's it, you have configured sendmail to act as a smarthost.
Configuring Your SMTP Server To accept mails from Smarthosts:
NOTE: This procedure is applicable only if the remote live smtp server is a sendmail server, which is true in this scenario. For other SMTP servers refer to their documentation.
Presumptions: The live SMTP server is already using FEATURE ('access_db'..
Edit the access file in the live smtp server to accept mails from the smart host.
Rebuild the Access database file.
#/usr/sbin/makemap hash access < accessRestart the sendmail service.
root@smtp# service sendmail restartThat's it; the remote smtp server will accept mails from the smarthost.