Setting the Postfix mail in Ubuntu
I am DevOps Engineer who works on DevOps tools like Docker, Kubernetes, Terraform, Git, GitHub, Jenkins and AWS services.
Install postfix
apt install postfix
install mailx
apt install mailutils
In the /etc/postfix/main.cf file, add -
relayhost = [smtp.gmail.com]:587 # Location of sasl_passwd we saved smtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd # Enable 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
Create file under /etc/postfix/sasl/
Filename: sasl_passwd
Add the below line -
[smtp.gmail.com]:587 <your email>:<your password>
Ex- [smtp.gmail.com]:587 bhaskarmehta422@gmail.com:aasajrjiszawigyw
Steps to set the Password -
Go to this location in your browser and click on "Manage your Google Account"

Click On Security -

And make sure that 2 Steps Verification is ON -

3. Search App passwords in the search bar and click on this -

4. Click on Select App and Click on (Other)Custom Name. Give a name example - smtp and click on Generate.

-> Once you click on Generate, it will generate a password for you and you can use this here.

Convert the sasl_passwd file into db file from /etc/postfix/sasl location
postmap sasl_passwd
change the owenership of sasl_passwd
chmod 600 *
Start the Postfix service
systemctl start/enable postfix
systemctl stop/disable postfix
systemctl restart postfix
systemctl status postfix
Send a test email
echo "Test Mail" | mail -s "Postfix TEST" -A testfile.txt bhaskarmehta422@gmail.comOutput -

