sasl_passwd
vim main.cf
{ADD THE FOLLOWING LINES}
relayhost = [smtp.gmail.com]:587
myhostname = <your hostname/SURAJ-LAPTOP>
587 is the port for secure TLS
To check your hostname use “hostname -f”
#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
3.) now create a file at /etc/postfix/sasl/ named sasl_passwd
cd /etc/postfix/sasl/
vim sasl_passwd
Add the below line and change the “email.gmail” to your Gmail.
[smtp.gmail.com]:587 email@gmail.com:<password>
Go to mail which is used here and go to security and ENABLE 2-STEP VERIFICATION
Now go to app passwords in security => Click on select app => Choose other
Write “smtp” and click on generate
It will show a window in which a password is written. Copy the password and paste it in the above file “sasl_passwd” at <password>.
4.) Convert the sasl_passwd file into db file
postmap /etc/postfix/sasl/sasl_passwd
a new file sasl_passwd.db is created here
as it contain sensitive info so we only allow user to read and write permissions on this file
chmod 600 /etc/postfix/sasl/*
5.) start the postfix service
# To start the postfix service
systemctl start/enable postfix
# To stop the postfix service
systemctl stop/disable postfix
# To re-start the postfix service
systemctl restart postfix
6.) How to send an email
echo "Test Mail" | mail -s "Postfix TEST" email@gmail.com
7.) If you encounter any kind of error then go to main.cf file and comment on the line
# smtp_tls_security_level = may
After editing the file do
systemctl restart postfix.service
8.) to attach any file with the mail
Create a file testfile
vim testfile
#write something in the file to verify
"Suraj soni attach a file with the mail"
Save the file
echo "Test Mail" | mail -s "Postfix TEST" -a <filename/testfile> email@gmail.com
LLL