• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How To Masquerade Sender Address In Sendmail in CentOS/RHEL

by admin

You would like to configure your sendmail server to masquerade the sender address to no-reply@target-domain.net when sending emails from it.

The Solution

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.

target-domain.net

5. Fill /etc/mail/genericstable.

root no-reply@target-domain.net
other-user1 no-reply@target-domain.net
other-user2 no-reply@target-domain.net

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" your-name@your-email.com

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.

Filed Under: CentOS/RHEL 5, CentOS/RHEL 6, Linux

Some more articles you might also be interested in …

  1. calcurse: command not found
  2. CentOS / RHEL 6 : How to disable telnet service
  3. cupsd: Server daemon for the CUPS print server
  4. gnome-terminal: command not found
  5. mkfs.exfat: command not found
  6. a2enconf: command not found
  7. a2ensite: command not found
  8. getfacl: command not found
  9. What is the purpose of “wheel” group in Linux
  10. aws codecommit: AWS CodeCommit is a managed source control service that hosts private Git repositories

You May Also Like

Primary Sidebar

Recent Posts

  • “glab issue” Command Examples
  • “glab auth” Command Examples
  • “glab alias” Command Examples
  • gixy Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright