Cloud and Self-Hosting
Configure Postfix to Use Gmail SMTP on Ubuntu
By Amjid Ali · · Updated · 1 min read

In this article
Relaying Postfix mails via smtp.gmail.com:
First, install all necessary packages:
sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
If you do not have postfix installed before, postfix configuration wizard will ask you some questions. Just select your server as Internet Site and for FQDN use something like mail.example.com
Open Configuration File
vim /etc/postfix/main.cf
Look for the Configuration and change the line as below
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes
You might have noticed that we haven’t specified our Gmail username and password in above lines.
They will go into a different file. Open/Create
vim /etc/postfix/sasl_passwd
And add following line:
[smtp.gmail.com]:587 emailid@gmail.com:password
Fix permission and update postfix config to use sasl_passwd file:
sudo chmod 400 /etc/postfix/sasl_passwd sudo postmap /etc/postfix/sasl_passwd
Next, validate certificates to avoid running into error. Just run following command:
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
Finally, reload postfix config for changes to take effect:
sudo /etc/init.d/postfix reload
Now sent the Email to test
Check if mails are sent via Gmail SMTP server
If you have configured everything correctly, the following command should generate a test mail from your server to your mailbox.
echo "Postfix Test by Amjid Ali" | mail -s "Test Ubutu PostFix Amjid" amjid@syncbricks.com
Thank You. Please dont’ forget to comment.
Keep reading
Cloud and Self-HostingInstalling Kubernetes Dashboard on a K3s High Availability Cluster (Ubuntu 24.04)The Kubernetes Dashboard is a browser-based UI that allows you to visualize, manage, and troubleshoot workloads and resources inside your Kubernetes clu... · 2 min read
Cloud and Self-HostingInstall a 3-Node HA Kubernetes (K3s) Cluster on Ubuntu Server 24.04 Step-by-Step (Proxmox/VM Friendly)Step-by-step guide to install a 3-node HA Kubernetes (K3s) cluster on Ubuntu Server 24.04 using Proxmox VMs. Includes setup, firewall rules, tokens, and verification. · 5 min read
Cloud and Self-HostingHow to Install and Configure n8n on Oracle Cloud Always Free VM (Ubuntu 24.04)n8n (short for nodemation) is an open-source workflow automation platform that allows you to connect applications and APIs, automate repetitive tasks, a... · 4 min read