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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. How to Remove a Dead Mulitpath Device without Reboot in CentOS/RHEL
  2. env Command Examples in Linux
  3. How to disable NetworkManager on CentOS / RHEL 7
  4. Examples of using dmsetup command in Linux
  5. nm : Command to list the symbols in object files.
  6. lvchange Command Examples in Linux
  7. Oracle Software Group Accounts OSDBA, OSOPER, Oracle Inventory group
  8. XFS Filesystem Gets Mounted As Readonly (CentOS/RHEL)
  9. pvcreate error : Can’t open /dev/sdx exclusively. Mounted filesystem?
  10. How to install CentOS / RHEL 7 on RAID Partition

You May Also Like

Primary Sidebar

Recent Posts

  • JavaFX ComboBox: Set a value to the combo box
  • Nginx load balancing
  • nginx 504 gateway time-out
  • Images preview with ngx_http_image_filter_module

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright