Sendmail is a widely used Mail Transfer Agent (MTA) for sending and receiving email on Linux systems. It handles routing email messages between senders and recipients as well as delivering messages locally.
While Ubuntu 22.04 comes preconfigured with a basic sendmail server, you may want more customization and security hardening for production environments. This guide covers key steps to properly configure sendmail in Linux / Ubuntu 22.04 LTS release.
If not already present, install sendmail using apt:
sudo apt install sendmail
This will install the sendmail package along with dependencies like mailutils.
The main sendmail configuration file is /etc/mail/sendmail.cf. Rather than editing it directly, you can include custom settings in /etc/mail/sendmail.mc which then generates the final sendmail.cf.
Some common settings to adjust in sendmail.mc include:
Mail domain name – Set your canonical domain used for emails:
DOMAIN(generic)dnl
Smart host – Specify an external mail relay for outbound messages:
define(`SMART_HOST’, `email-relay.example.com’)dnl
Masquerading – Mask internal IP addresses to the domain name for outbound mail:
MASQUERADE_AS(example.net)dnl
See man sendmail.cf for other parameters like maximum message size, listening interfaces/IPs, security settings and more.
After updating sendmail.mc, generate an updated sendmail.cf:
sudo m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
Restart sendmail to apply the new configuration:
sudo systemctl restart sendmail
Read: Best Email clients of 2023
Sendmail has some default security, but here are extra recommendations for improving security:
Adjust your sendmail.mc configuration to apply these security hardening steps.
The default local mail server on Ubuntu is Postfix. To make sendmail collaborate with Postfix for delivering local mail:
2. Create /etc/postfix/mailbox_command with:
/usr/sbin/sendmail -i -oem -oi -t
3. Set file permissions:
chmod 755 /etc/postfix/mailbox_command
4. Restart both Postfix and Sendmail:
This will handoff messages to Sendmail for final local delivery.
Read: How to setup Postfix mail server on Ubuntu using SquirrelMail
To verify Sendmail is running and check status, use:
sudo systemctl status sendmail
This will report if the service is active and any errors.
If having problems with sent mail, check Sendmail logs:
Some common errors include:
Adjust configurations and firewall rules as needed to resolve.
Read: How to list, start and stop services at boot time in Linux Ubuntu/Debian
Make sure to tune Sendmail properly on high-traffic servers:
Benchmark and load test to identify and fix bottlenecks.
Read: How to speed up Linux
Running a mail server comes with complex challenges. But having the right knowledge and tools can make all the difference. Here are 6 tips based on surveys of over 500 professional mail administrators:
Undelivered messages within Sendmail are held in a designated queue. Oversight of this queue is accomplished through the utilization of the ‘mailq’ command.
Read: Securing Ubuntu: Best Practices for Keeping Your System Safe
For a real-time display of the existing queue, execute the following command with superuser privileges:
sudo mailq
To take direct control and endeavor to dispatch any messages lingering in the queue, perform the subsequent command:
sudo sendmail -q
To enhance spam and unwanted email mitigation, configure Sendmail to employ Real-time Blackhole Lists (RBLs). These lists encompass IP addresses with established records as sources of spam. Enabling RBLs involves appending the subsequent line to the ‘/etc/mail/sendmail.mc’ file:
FEATURE(`dnsbl’, `zen.spamhaus.org’, `”554 Rejected – see http://www.spamhaus.org/query/bl?ip=”$&{client_addr}’)dnl
Subsequently, regenerate the ‘/etc/mail/sendmail.cf’ file and perform a Sendmail service restart post any configuration modifications.
To prevent potential data loss due to system failures or inadvertent removal, it’s advisable to consistently create backups of your Sendmail configuration files. This includes files like ‘/etc/mail/sendmail.mc’ and ‘/etc/mail/sendmail.cf’.
The post How to Configure Sendmail on Ubuntu 22.04 appeared first on net2.
Canonical’s Kubernetes LTS (Long Term Support) will support FedRAMP compliance and receive at least 12…
Welcome to the Ubuntu Weekly Newsletter, Issue 878 for the week of February 2 –…
At Canonical, we firmly believe that delivering an outstanding, customer-centric support experience is impossible without…
I want to share how to install osTicket v1.14 for Ubuntu 20.04 server. osTicket written…
Now I want to share how to install WordPress on ubuntu 20.04 server. WordPress is…
Now I want to share the DNS server installation process on your Ubuntu 20.04 server.…