Using Sendmail to Change the Sender's Email Address
Sometimes masquerading isn't enough. At times you may need to change not only the domain of the sender but also the username portion of the sender's e-mail address. For example, perhaps you bought a program for your SOHO office that sends out notifications to your staff, but the program inserts its own address as sender's address, not that of the IT person.
Web-based CGI scripts tend to run as user apache and, therefore, send mail as user apache too. Often you won't want this, not only because apache's e-mail address may not be a suitable, but also because some anti-spam programs check to ensure that the From:, or source e-mail address, actually exists as a real user. If your virtusertable file allows e-mail to only predefined users, then queries about the apache user will fail, and your valid e-mail may be classified as being spam.
With sendmail, you can change both the domain and username on a case-by-case basis using the genericstable feature:
1) Add these statements to your /etc/mail/sendmail.mc file to activate the feature:
FEATURE(`genericstable',`hash -o /etc/mail/genericstable.db')dnl
GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')dnl
2) Create a /etc/mail/generics-domains file that is just a list of all the domains that should be inspected. Make sure the file includes your server's canonical domain name, which you can obtain using the command:
sendmail -bt -d0.1 </dev/null
Here is a sample /etc/mail/generics-domains file:
my-site.com
another-site.com
bigboy.my-site.com
3) Create your /etc/mail/genericstable file. First sendmail searches the /etc/mail/generics-domains file for a list of domains to reverse map. It then looks at the /etc/mail/genericstable file for an individual email address from a matching domain. The format of the file is
linux-username username@sisrv.net
Here is an example:
alert security-alert@sisrv.net
peter urgent-message@sisrv.net
apache mailer@sisrv.net
4) Run the sendmail restart script from the beginning of the chapter and then test.
Your e-mails from linux-username should now appear to come from username@sisrv.net.
The other option is to edit /etc/mail/sendmail.mc
Go at the bottom of the file and edit this code:
dnl # Masquerading options
FEATURE(`always_add_domain')dnl
MASQUERADE_AS(`sisrv.net')dnl
FEATURE(`allmasquerade')dnl
FEATURE(`masquerade_envelope')dnl
Replace sisrv.net with your domain and than restart sendmail
sudo service sendmail restart
We hope this did solve your sendmail issue, good luck.