Tuesday, July 30, 2024

How to Configure Postfix with Gmail SMTP on Ubuntu

 

In this blog, we will configure Gmail SMTP with Postfix to manage system log report emails and ensure they are received in your inbox.

Prerequisites:

Set up Gmail SMTP configuration Link

What is Postfix?

Postfix is a free and open-source mail transfer agent(MTA) that routes and delivers E-mail.


Here are the main steps to configure Postfix as an SMTP relay.

Install Postfix:

sudo apt-get update
sudo apt-get install postfix

Configure Postfix:
Open the Postfix main configuration file:

sudo nano /etc/postfix/main.cf

Modify below line:

relayhost = [smtp.gmail.com]:587

Add the following lines at the bottom:

smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

Set Up Authentication:

Create the /etc/postfix/sasl_passwd file and add your SMTP server's login details:

[smtp.gmail.com]:587    your-email@gmail.com:your-password

Secure the file and convert it to a format Postfix can use:

sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd

Reload Postfix:

sudo systemctl reload postfix

Test the Configuration:
Send a test email to verify that your SMTP relay is working correctly:

echo "Test Postfix Gmail SMTP Relay via Tech2Towards" | mail -s "Test Postfix" recipient@example.com
 

No comments:

Post a Comment

testing