Setting Up and Configuring Postfix on Ubuntu for Efficient Email Management

Setting Up and Configuring Postfix on Ubuntu for Efficient Email Management

What is Postfix?

Postfix is an open-source Mail Transfer Agent (MTA) used to route and deliver email. Its primary role is to relay email messages between servers, ensuring smooth delivery of both incoming and outgoing emails. It is highly efficient, designed to be secure and fast, and is the default MTA on many Linux distributions, including Ubuntu.

Install Postfix

Start by installing Postfix and the mailutils package, which includes basic utilities for testing and sending emails from the command line.

sudo apt update
sudo apt install postfix mailutils

Basic Configuration of Postfix

Once Postfix is installed, you need to configure it for your domain and mail routing. The primary configuration file for Postfix is located at:

/etc/postfix/main.cf

In main.cf add relayhost

relayhost = [smtp.gmail.com]:587

smtp_sasl_passwd_maps = hash:/etc/postfix/sasl/sasl_passwd
smtp_sasl_auth_enable = yes
smtp_sasl_security_options - noanonymous

Create the sasl_passwd file:

sudo nano /etc/postfix/sasl_passwd

[smtp.gmail.com]:587 sanketshirke10@gmail.com:password

After Creating sasl_password file , Create sasl_password.db file

postmap sasl_passwd

After making the necessary changes, restart Postfix to apply the new configuration:

sudo systemctl enable postfix
sudo systemctl start postfix

Test the SMTP Relay

echo "This is a test email." | mail -s "Test Email" recipient@example.com

Verify and Troubleshoot