#Postfix install sudo apt-get install postfix libsasl2-modules mailutils #select intener site and put the email domain #create in /etc/postfix/sasl_passwd nano /etc/postfix/sasl_passwd ## and add [smtp.gmail.com]:587 username@gmail.com:password #charge the pass to db sudo postmap /etc/postfix/sasl_passwd #only root can see files with passwords (use one of the 2 options) sudo chown root:root /etc/postfix/sasl/sasl_passwd /etc/postfix/sasl/sasl_passwd.db sudo chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db #config mainfile in /etc/postfix/main.cf nano /etc/postfix/main.cf #change relayhost = [smtp.gmail.com]:587 #and add to the end ########################### # enable SASL authentication smtp_sasl_auth_enable = yes # disallow methods that allow anonymous authentication. smtp_sasl_security_options = noanonymous # where to find sasl_passwd smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd # Enable STARTTLS encryption smtp_use_tls = yes # where to find CA certificates smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt ############################ #restart with systemctl sudo systemctl restart postfix #do a test sendmail recipient@gmail.com FROM: youremail@gmail.coms SUBJECT: Hello from your server! This is a test email sent from your server by Postfix. . #check in the logs and the email nano /var/log/mail.log (or mail.err) #if something is wrong, can reconfig postfix with this sudo dpkg-reconfigure postfix #also can check allias nano /etc/aliases ####flush mails########### #View queued postqueue -p #Flush queued mail postqueue -f #Purge 1 msg postsuper -d [message id] #Purge all sudo postsuper -d ALL