How to setup sendmail in ubuntu?

Sendmail is a powerful and reliable mail transfer agent (MTA) that efficiently handles large volumes of email on Linux systems. It works by accepting email messages from local or remote mail clients and relaying them to destination mail servers using the Simple Mail Transfer Protocol (SMTP).

This article provides a comprehensive guide on installing and configuring Sendmail on Ubuntu systems, covering everything from basic setup to advanced configuration options.

Installing Sendmail on Ubuntu

Begin by updating your package list and installing Sendmail using the following commands:

sudo apt-get update
sudo apt-get install sendmail

This downloads and installs the Sendmail package along with its dependencies on your Ubuntu system.

Configuring Sendmail

Sendmail's main configuration file is located at /etc/mail/sendmail.cf, but you should never edit this file directly. Instead, use the sendmail.mc macro configuration file to generate the main configuration:

sudo nano /etc/mail/sendmail.mc

Basic Configuration Settings

Add these common configuration options to your sendmail.mc file:

define(`_CLASS_A_NET', `10.0.0.0/8')dnl
define(`_CLASS_B_NET', `172.16.0.0/12')dnl
define(`_CLASS_C_NET', `192.168.0.0/16')dnl
define(`_MAX_MESSAGE_SIZE',`10000000')dnl
define(`_QUEUE_DELIVERY', `30m')dnl

These settings define IP address ranges allowed to relay email, set the maximum message size to 10MB, and specify the queue delivery timeout to 30 minutes.

Generating the Configuration File

After modifying sendmail.mc, generate the main configuration file:

sudo m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

Starting and Managing Sendmail Service

Start the Sendmail service and enable it to run at boot:

sudo systemctl start sendmail
sudo systemctl enable sendmail

Check the service status to ensure it's running properly:

sudo systemctl status sendmail

Testing Sendmail Configuration

Send a test email to verify that Sendmail is working correctly:

echo "This is a test email" | mail -s "Test email" your@email.com

Replace your@email.com with your actual email address. If you receive the email, Sendmail is configured properly.

Advanced Configuration Options

Relay Configuration

Configure Sendmail to relay emails for specific domains:

FEATURE(`relay_hosts_only')dnl
FEATURE(`access_db')dnl
RELAY_DOMAIN(yourdomain.com)dnl

Virtual Domains Support

Enable support for multiple virtual domains:

FEATURE(`virtusertable', `hash -o /etc/mail/virtusertable')dnl
VIRTUSER_DOMAIN_FILE(`/etc/mail/virtusertable')dnl

Anti-Spam Configuration

Implement basic anti-spam measures:

FEATURE(`dnsbl', `dnsbl.sorbs.net')dnl
FEATURE(`blacklist_recipients')dnl
FEATURE(`badmx', `dnsbl.sorbs.net')dnl

Troubleshooting Common Issues

If you encounter problems, check the Sendmail logs for error messages:

sudo tail -f /var/log/mail.log

Common issues include firewall blocking port 25, DNS resolution problems, or incorrect relay configurations. Ensure that your system's hostname is properly configured and that DNS records are set up correctly.

Integration with Web Applications

Web applications like WordPress or Drupal can use Sendmail as their mail transport agent. Configure the application to use /usr/sbin/sendmail as the mail executable path. This ensures reliable email delivery from your web applications.

Conclusion

Sendmail is a robust MTA solution for Ubuntu systems, offering extensive configuration options for handling email efficiently. With proper setup and configuration, it provides reliable email services for both local and remote delivery, making it suitable for various server environments.

Updated on: 2026-03-17T09:01:38+05:30

19K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements