You would like to configure your sendmail server to masquerade the sender address to firstname.lastname@example.org when sending emails from it.
Normally to masquerade a domain, the “MASQUERADE_AS” and “MASQUERADE_DOMAIN” is used in /etc/mail/sendmail.mc. But that will leave the user unchanged. With sendmail, you can change both the domain and username on a case-by-case basis using the genericstable feature.
1. make sure all the “MASQUERADE” items are commented out in /etc/mail/sendmail.mc. Be noted the lines starting with “dnl” are meant to be commented.
# grep 'MASQUERADE' /etc/mail/sendmail.mc dnl # MASQUERADE_AS(`target-domain.net')dnl dnl MASQUERADE_DOMAIN(localhost)dnl dnl MASQUERADE_DOMAIN(localhost.localdomain)dnl dnl MASQUERADE_DOMAIN(domain-to-masquerade.net)dnl
2. Enable domaintable feature:
# grep domaintable sendmail.mc FEATURE(domaintable)
# cat domaintable domain-to-masquerade.net target-domain.net
3. Configure “genericstable” in /etc/mail/sendmail.mc by adding the following lines in it.
FEATURE(`genericstable',`hash -o /etc/mail/genericstable.db')dnl GENERICS_DOMAIN_FILE(`/etc/mail/generics-domains')dnl
4. Fill /etc/mail/generics-domains.
5. Fill /etc/mail/genericstable.
root email@example.com other-user1 firstname.lastname@example.org other-user2 email@example.com
6. Recompile /etc/sendmail.mc:
# cd /etc/mail # make
You may get the following error while doing so:
# make WARNING: 'sendmail.mc' is modified. Please install package sendmail-cf to update your configuration.
It is due to missing of sendmail-cf package and please install it to proceed.
# yum install sendmail-cf
# cd /etc/mail # make
7. Restart sendmail service.
# service sendmail restart Shutting down sm-client: [ OK ] Shutting down sendmail: [ OK ] Starting sendmail: [ OK ] Starting sm-client: [ OK ]
8. Test and verify.
# hostname domain-to-masquerade.net
# echo "This is a test mail to verify the sendmail sender masquerade." | mailx -s "Test Sender Masquerade" firstname.lastname@example.org
Make sure “target-domain.net” are Full Qualified Domain Name(FQDN). That means the domain name should be resolvable by the target mail server from the authoritative DNS servers. Otherwise, the mail will most likely be rejected.