Tutorial for Setting Up a Postfix Smtp Gmail Mail Server on Linux
This tutorial will guide you through the process of setting up a Postfix SMTP Gmail mail server on CentOS 8. Postfix is a popular open source mail server used on Linux systems to relay emails.
Before you begin, make sure you have the following installed and up to date:
• Centos 8
• Sendmail
• Postfix
• Cyrus-sasl-plain
sudo dnf install sendmail
sudo dnf install postfix
sudo dnf install cyrus-sasl-plain
Step 1: Configure the Main Postfix Configuration File
Open the Postfix main configuration file using the vi command:
sudo vi /etc/postfix/main.cf
Add the following lines to the file:
meta_directory = /etc/postfix
shlib_directory = /usr/lib64/postfix
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
# Enable STARTTLS encryption
smtp_tls_security_level = encrypt
Step 2: Configure the SASL Password File
Open the SASL password file using the vi command:
sudo vi /etc/postfix/sasl_passwd
Add the following line to the file, replacing <your_smtp_gmail_address> and <your_gmail_app_password> with your Gmail address and app password:
[smtp.gmail.com]:587 <your_smtp_gmail_address>:<your_gmail_app_password>
Step 3: Create the Postmap Database
Create the Postmap database using the postmap command:
sudo postmap /etc/postfix/sasl_passwd
Step 4: Restart the Postfix Service
Restart the Postfix service using the service command:
sudo service postfix restart
Step 5: Test the Mail Server
To test the mail server, run the following command, replacing [email protected] with your recipient’s email address:
echo "Test email" | sendmail -s "Test Email Subject" test@gmail.com
If the mail server is functioning correctly, you should
Step 6: Verify the Mail Server
To verify that the mail server is working properly, use the mailq command to check the mail queue. If the mail queue is empty, the server is functioning correctly. If there are emails in the queue, there may be errors in the configuration that need to be addressed.
Congratulations! You have successfully configured a Postfix SMTP Gmail mail server on CentOS 8.