Sendmail is a popular mail transfer agent used to send and receive emails on Unix-based systems. By default, when you send an email using Sendmail, the "From" header in the email will be set to the username of the account from which the email is being sent. However, there may be situations where you would like to change the "From" header to a different email address. In this article, we will explain how to change the "From" header in Sendmail.
Step 1: Edit the Sendmail Configuration File
The first step is to edit the Sendmail configuration file, which is typically located at /etc/mail/sendmail.cf. Open this file using a text editor of your choice.
Look for the line that starts with Dj. This line specifies the default domain name used by Sendmail. By default, it is usually set to the fully qualified domain name of your server. You need to change this line to the domain name you want to use in the "From" header. For example, if you want to use example.com as the domain name, the line should look like this:
Djexample.com
Save the changes to the configuration file and exit the text editor.
Step 2: Create a Mail Aliases File
Next, you need to create a mail aliases file, which will map the email address you want to use in the "From" header to the actual account that will receive the email. Open a new file using a text editor and enter the following line:
from-address: actual-account
Replace from-address with the email address you want to use in the "From" header, and actual-account with the actual account that will receive the email. Save the file with a name of your choice, such as mail-aliases.
Step 3: Configure Sendmail to Use the Mail Aliases File
Now, you need to configure Sendmail to use the mail aliases file you created. Open the Sendmail configuration file again (/etc/mail/sendmail.cf) and look for the line that starts with Kaliases. Uncomment this line by removing the leading # character.
Next, find the line that starts with AliasFile. Uncomment this line as well, and change the path to the location of your mail aliases file. For example, if you saved the file as mail-aliases in the /etc/mail directory, the line should look like this:
AliasFile /etc/mail/mail-aliases
Save the changes to the configuration file and exit the text editor.
Step 4: Restart Sendmail
Finally, you need to restart the Sendmail service for the changes to take effect. Open a terminal window and run the following command:
sudo service sendmail restart
Enter your password when prompted, and the Sendmail service will restart.
That's it! You have successfully changed the "From" header in Sendmail. When you send an email now, the "From" header will be set to the email address you specified in the mail aliases file.
Conclusion
In this article, we have explained how to change the "From" header in Sendmail. By following these steps, you can easily customize the "From" header to use a different email address. This can be useful in various scenarios, such as when you want to send emails on behalf of a different account or organization.
References
| Source | Link |
|---|---|
| Sendmail Documentation | https://www.sendmail.com/sm/open_source/docs/configuration_readme/ |
| Linux man page - sendmail | https://man7.org/linux/man-pages/man8/sendmail.8.html |