SMTP short form of Simple Mail Transfer Protocol. A protocol for sending e-mail messages between servers. Most e-mail systems that send mail over the Internet use SMTP to send messages from one server to another; the messages can then be retrieved with an e-mail client using either POP or IMAP. In addition, SMTP is generally used to send messages from a mail client to a mail server. This is why you need to specify both the POP or IMAP server and the SMTP server when you configure your e-mail application.
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
If you have configured everything correctly, following command should generate a test mail from your server to your mailbox.
Install all necessary packages:
sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
If you do not have postfix installed before, postfix configuration wizard will ask you some questions. Just select your server as Internet Site and for FQDN use something like mail.example.comThen open your postfix config file:
sudo gedit /etc/postfix/main.cf
and following lines to it:
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes
You dont want to specified our Gmail username and password in above lines. They will go into a different file. Create a new file and add the Gmail credentials in it.smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes
sudo gedit /etc/postfix/sasl_passwd
And add following line:
[smtp.gmail.com]:587 USERNAME@gmail.com:PASSWORD
If you have a Google App’s domain, replace @gmail.com with your @domain.comFix permission and update postfix config to use sasl_passwd file:
sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
validate certificates to avoid errors:
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
Finally, reload postfix config for changes to take effect:
sudo /etc/init.d/postfix reload
Testing if mails are sent via Gmail SMTP server:
If you have configured everything correctly, following command should generate a test mail from your server to your mailbox.
echo "Test mail from Postfix SMTP Server" | mail -s "Test Postfix" you@example.com
Please note that Gmail’s SMTP server has a limit of 500 emails per day.
Post a Comment