Sendmail is a widely used Mail Transfer Agent (MTA) that allows users to send and receive email on Linux systems. It is a powerful and flexible mail server solution that can be configured to work with various email clients and services. In this article, we will provide you with a comprehensive guide to understanding, installing, and configuring Sendmail on Fedora. We will also cover some tips and tricks for mail server administrators to ensure efficient and secure operation.
Prerequisites
Before you begin, ensure that you have the following:
- A Fedora system (we will use Fedora 37 in this guide, but the process should be similar for other versions)
- A stable internet connection
- Root or sudo privileged account access
Step 1: Update your system
Before installing Sendmail, update your Fedora system to ensure that you have the latest packages and security patches. Open a terminal and run the following command:
sudo dnf update -y
Step 2: Install Sendmail and related packages
To install Sendmail along with related packages, such as mailutils and sendmail-cf, run the following command:
sudo dnf install -y sendmail sendmail-cf mailutils
Step 3: Configure Sendmail
The main configuration file for Sendmail is /etc/mail/sendmail.cf. However, it is recommended to make changes to the .mc file (e.g., /etc/mail/sendmail.mc) and then generate the .cf file. This makes the configuration process easier and less error-prone.
- To configure Sendmail, open the /etc/mail/sendmail.mc file using your preferred text editor:
sudo nano /etc/mail/sendmail.mc
- Ensure the following lines are present and uncommented in the file:123define(`SMART_HOST', `your.smtp.server')dnldefine(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnlFEATURE(`authinfo',`hash -o /etc/mail/authinfo.db')dnl
Replace “your.smtp.server” with the address of your SMTP relay or smart host.
Step 4: Set up authentication (optional)
If your SMTP server requires authentication, create the /etc/mail/authinfo file:
sudo nano /etc/mail/authinfo
Add the following contents:
1 | AuthInfo:your.smtp.server "U:your_username" "P:your_password" "M:PLAIN" |
Replace “your.smtp.server”, “your_username”, and “your_password” with the appropriate values for your SMTP server.
To create the authentication database, run:
sudo makemap hash /etc/mail/authinfo < /etc/mail/authinfo
Step 5: Generate the Sendmail configuration file
After making changes to the /etc/mail/sendmail.mc file, you need to generate the /etc/mail/sendmail.cf file. Run the following command:
sudo make -C /etc/mail
Step 6: Start and enable the Sendmail service
Enable the Sendmail service to start automatically on boot:
sudo systemctl enable sendmail.service
Start the Sendmail service:
sudo systemctl start sendmail.service
Step 7: Test your Sendmail configuration
To test your Sendmail configuration, use the mail command to send a test email:
echo "This is a test email." | mail -s "Test Email" [email protected]
Replace "[email protected]" with a valid email address. Check the recipient's inbox to confirm that the email was delivered successfully.
Tips and Tricks for Mail Server Administrators
- Monitor Sendmail logs: Keep an eye on Sendmail logs to ensure smooth operation and diagnose any issues. Sendmail logs can be found at /var/log/maillog. Use the tail command to view the latest log entries:
sudo tail -f /var/log/maillog
- Manage the mail queue: Sendmail stores undelivered messages in a queue. You can manage the queue using the mailq command. To view the current queue, run:
sudo mailq
To manually process the queue and attempt to send any queued messages, run:
sudo sendmail -q
- Limit spam and unwanted emails: Configure Sendmail to use Real-time Blackhole Lists (RBLs) to reduce the amount of spam and unwanted emails. RBLs are lists of IP addresses known to be sources of spam. To enable RBLs, add the following line to your /etc/mail/sendmail.mc file:1FEATURE(`dnsbl', `zen.spamhaus.org', `"554 Rejected - see http://www.spamhaus.org/query/bl?ip="$&{client_addr}')dnl
Remember to regenerate the /etc/mail/sendmail.cf file and restart the Sendmail service after making changes to the configuration.
- Secure your mail server: Ensure that your mail server is secure by implementing SSL/TLS encryption, using strong authentication mechanisms, and keeping your software up-to-date. Also, configure your firewall to only allow necessary traffic.
- Backup your configuration: Regularly back up your Sendmail configuration files, such as /etc/mail/sendmail.mc and /etc/mail/sendmail.cf, to avoid data loss in case of system failure or accidental deletion.
- Monitor system resources: Keep an eye on system resources, such as CPU usage, memory usage, and disk space, to ensure that your mail server is running optimally. Use tools like top, vmstat, and df to monitor resource usage.
Conclusion
By following this guide, you should now have a better understanding of Sendmail and its installation process on Fedora. We also provided some tips and tricks to help mail server administrators manage their systems effectively. With proper configuration and maintenance, Sendmail can provide a robust and reliable mail server solution for your Fedora system.
1 Comment
Thank you very much for this tutorial. In the past I’ve struggled to get sendmail working on new machines, and sometimes after an OS upgrade. This tutorial could have saved me a lot of wasted time. However there is a small item that could be added. My first attempt to use sendmail after following your instructions produced what seemed to be a ‘hung’ sendmail process, with this message:
‘sendmail.service: Can’t open PID file /run/sendmail.pid (yet?) after start: Operation not permitted’
After a little research I found the solution here: https://linuxconfig.org/sendmail-unqualified-hostname-unknown-sleeping-for-retry-unqualified-hostname
i.e.
sendmail is searching for a FQDN ( fully qualified domain name ). In our case the host name is “debian” and that is not a FQDN. To resolve this problem change /etc/hosts: FROM:
127.0.0.1 localhost
127.0.1.1 debian
TO:
127.0.0.1 localhost.localdomain localhost debian
127.0.1.1 debian
I suggest that your tutorial would be even more valuable to more people if you included that tip (replacing ‘debian’ with the hostname of the machine being used).
Thanks
Aaron Sloman