Sendmail Configuration postfix Install with Gmail SMTP
If You’r are running a Linux server and accept email, the only Sendmail Configuration is to use your mail service’s (SMTP) Simple Mail Transfer Protocol server.
Sendmail Configuration Google’s Gmail features a vigorous SMTP server that you simply can effectively arrange a Linux mail exchange specialist (MTA) like Sendmail or Postfix to utilize.
Prerequisites
- Need root access
- Gmail Account with “Less secure app access” enable.
Sendmail Configuration Action Plan:
Step 1:
Update the Package (optional)
sudo yum update -y
Step 2:
Install the mailx and postfix
sudo yum install postfix -y
sudo yum install mailx -y
Step 3:
Check the install mailx and postfix with version
rpm -qa | grep postfix
rpm -qa | grep mailx

Step 4:
change the directory ‘/etc/postfix/’ in the directory we see main.cf and make a backup the file
cp /etc/postfix/main.cf /etc/postfix/main.cf_backup

Step 5:
After the backup now we configure the main.cf Add the two below two lines to the respective location. for the hostname use
relayhost = [smtp.gmail.com]:587

myhostname= <your_hostname>

And add these lines in the last of the file main.cf
####################################################
# Location of sasl_passwd we saved
smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd
# Enables SASL authentication for postfix
smtp_sasl_auth_enable = yes
smtp_tls_security_level = encrypt
# Disallow methods that allow anonymous authentication
smtp_sasl_security_options = noanonymous

Step 6:
Create a directory ‘sals’ under ‘/etc/postfix/sasl/’
mkdir /etc/postfix/sasl/
Create a fie ‘sasl_passwd’under /etc/postfix/sasl/sasl_passwd
touch /etc/postfix/sasl/sasl_passwd
Step 7:
Generate an app password to use with Gmail’s SMTP server
sign in to the google account at the link below.
https://myaccount.google.com/intro/security
Go to the Security and scroll down enabled two-factor authentication.

in the search 🔎 box Search for the ‘app passwords’ and select it

Enter the app name EX: SMTP click on Create button

Notice the 16 digits password and copy the password

Step 8:
Add the below line In the file /etc/postfix/sasl/sasl_passwd relace your mail and password.
[smtp.gmail.com]:587 your_mail@gmail.com:generated_password

Step 9:
Use postmap for database converting, as we notice below .db extension
postmap /etc/postfix/sasl/sasl_passwd
Change the permissions.
chmod 600 /etc/postfix/sasl/*

Step 10:
Now we stop the sendmail if active
systemctl stop sendmail
Now we start the postfix
systemctl start postfix
systemctl enable postfix
systemctl status postfix

Step 11:
Now Testing the sendmail

The Output of the mail both Gmail and Outlook


The sendmail installed successfully.
Thank you