Configure Sendmail to Allow Specified Hosts to Send Emails from a Specific Domain
In certain scenarios, you may want to restrict Sendmail to allow only specific hosts to send emails from a specific domain. This is useful in situations where you want to prevent unauthorized hosts from sending emails using your domain, thereby improving email security and reducing the risk of email spoofing.
Prerequisites
Before we begin, it is assumed that you have Sendmail installed and configured on your system. If not, please install and configure Sendmail before proceeding.
Step 1: Define the Access Map
The first step is to define an access map that specifies the hosts that are allowed to send emails from the specific domain. This can be done by editing the /etc/mail/access file using a text editor of your choice.
Add the following line to the file:
To:*.example.com RELAY 192.168.1.100
In this example, we are allowing the host with IP address 192.168.1.100 to send emails from any address ending in @example.com. You can replace *.example.com with the specific email address or domain you want to allow.
Step 2: Create the Access Database
Once the access map has been defined, the next step is to create the access database. This can be done by running the following command:
makemap hash /etc/mail/access < /etc/mail/access
Step 3: Configure Sendmail
Finally, you need to configure Sendmail to use the access database. This can be done by editing the /etc/mail/sendmail.mc file using a text editor of your choice.
Add the following line to the file:
FEATURE(`access_db', `hash -T/etc/mail/access')
This line tells Sendmail to use the access database defined in the /etc/mail/access file.
Step 4: Reload Sendmail
Once the changes have been made, you need to reload Sendmail for the changes to take effect. This can be done by running the following command:
service sendmail reload
- Define an access map in the /etc/mail/access file that specifies the hosts allowed to send emails from the specific domain.
- Create the access database by running the
makemapcommand. - Configure Sendmail to use the access database by editing the /etc/mail/sendmail.mc file.
- Reload Sendmail for the changes to take effect.
References
Note: The above references are for Sendmail version 8.15.2.