Change Sender Address of Outbound Emails using SendMail

In this blog, we shall discuss how to change the sender address of outbound emails generated from a Sendmail server.

Why Do You Need This?

On a default setup, the emails sent out will have the header address set to <local-user>@<hostname>. You might need to rewrite these local addresses with a proper email address.
In the above image, you can see the local address apache@ip-xxxxxxxxxxxxxxxxx-compute-internal in the email header.

How You Do This?

Sendmail configuration is complex and you will need to read through the RFC documents of Sendmail to understand it completely. For those who don’t have the patience to do that ( like me ), here are the four simple steps to get this done.
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.In our case, just add the fully qualified hostname ( FQDN ) of the server. If you are on a Linux machine, you can get your FQDN by running the command “hostname -f” on the terminal.
Example
ip-172-31-1-179.us-west-2.compute.internal
 
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>@<new-domain>

Example Entries

Now, when a mail is sent as a root user or Apache user from the server, the header information will be rewritten to [email protected]
Sendmail uses/reads a hashed version of the file for better performance. So you will have to create a hashed version of the file.
makemap -r  hash /etc/mail/genericstable.db < /etc/mail/genericstable
4) Restart Sendmail
In the above image, you can see how Sendmail has rewritten the local addresses with the new address in the email headers.

Sparksupport’s Expertise in Email Configuration

At Sparksupport, we understand that proper email configuration is crucial for seamless communication and maintaining a professional image. Our team of experts excels in setting up and managing email servers, including advanced configurations like Sendmail. We ensure that your outbound emails have the correct header information, enhancing deliverability and credibility. Whether you’re dealing with complex Sendmail settings or other email server configurations, Sparksupport provides tailored solutions to meet your specific needs, ensuring your email communications are efficient and reliable.

Leave a Reply

Your email address will not be published. Required fields are marked *