A few days ago, email notifications from the server that went to email, mostly went to the spam box. Also when I tried the forgot password feature of one of the WordPress-based sites, the email that was sent did not come in. One of the two is the weakness if the email is sent via the server, it is not reliable alias it is stable if the child's language is now :)
For that, I have to use External SMTP Server to replace the email system on the web server. There are many choices of External SMTP Server, which is quite a fancy name SendGrid, Mandrill by MailChimp and Amazon SES (Simple Email Service). Or you can just googling keywords "SMTP Server Services" or for those who hunt for free services can use keywords "Free SMTP Server Service". And here is a tutorial on installing Postfix using the SMTP Server to send more reliable emails.
- This tutorial has been tried and worked on Debian 8 Linux, but it doesn't fail that it might work on Debian version 7 or other Debian-based linux variants, such as Ubuntu or KNOPPIX.
- The SMTP Server that I successfully tried was SendGrid; but this tutorial can also be used using other external SMTP server
- This tutorial cannot be used using Google's SMTP server (Gmail and Google Apps), if there is time I will write a separate tutorial.
Ok next step.
Before starting this tutorial, you already have:
- Servers, either Dedicated Server or VPS, have Debian 8 Linux installed.
- Fully Qualified Domain Name (FQDN) has been set on the server. Type the command
hostnamefor the check.
- Update the Linux packages with the command
apt-get update && apt-get upgrade
- You already have the SMTP server username & password.
- Make sure the module libsasl2-modules already installed, if not already use the command
apt-get install libsasl2-modules
NOTE: If your server is running Ubuntu, add
sudo to execute the above commands.
Type the command
apt-get install postfix mailutils
to start installing Postfix.
During the installation process, a dialog window will appear General type of mail configuration as follows.
choose Internet Site.
Then enter FQDN as below, for example fqdn.example.com
After the installation process is complete, open the Postfix configuration file with the command
Confirm parameters myhostname filled in according to your FQDN
myhostname = fqdn.example.com
Configure SMTP Username & Password
Username and password will be saved file named
passwd in the directory
/ etc / postfix / sasl /. Next, we will create a passwd file containing the SMTP server username & password which Postfix will use later.
If You Use SendGrid
Login to SendGrid, select menu Settings -> API Keys. Then click the button Create API Key.
Give the name of the API Key that will be created. And on choice API Key Permissions, choose Full Access. See the picture below.
Then click the button Create & View. On the next page, the API Key will appear, copy and paste the API Key into notepad.
Next we will create a file
passwd with orders
nano / etc / postfix / sasl / passwd
and enter the API Key that we created earlier, with a format like this
[smtp.sendgrid.net]: 587 apikey: APIkey code
NOTE: apikey is the SMTP username, leave it like that. Moderate code APIkey is the API Key that we created above. While 587 is the port used by SendGrid.
Then we will create a file hash db for Postfix by running the command
postmap / etc / postfix / sasl / passwd
If successful, a file will appear
passwd.db in the directory
/ etc / postfix / sasl /. Can check with orders
ls -l / etc / postfix / sasl /
To make the passwd and passwd.db files more secure, we will set them up so that only root can read and modify them; and also we will change the ownership of these files to root. Use this command:
chown root: root / etc / postfix / sasl / passwd /etc/postfix/sasl/passwd.db
chmod 0600 / etc / postfix / sasl / passwd /etc/postfix/sasl/passwd.db
Next, we will configure the
/etc/postfix/main.cf, so that Postfix can use the SendGrid SMTP server. Type the command
Change the relayhost according to SendGrid parameters
# SMTP host from SendGrid relayhost = [smtp.sendgrid.net]: 587
Then at the end of the file
/etc/postfix/main.cf, add this parameter
# enable SASL authentication smtp_sasl_auth_enable = yes # turn off anonymous authentication methods smtp_sasl_security_options = noanonymous # sasl location passwd smtp_sasl_password_maps = hash: / etc / postfixls etc / certificates STTP_tl_tltlScAt 1TP_tl_tile_certs /ca-certificates.crt
Save the changes above and restart Postfix with the command
service postfix restart
Next, test Postfix to send an email with the command
echo "email body" | mail -s "This is Email Title" -a "From: firstname.lastname@example.org" email@example.com
NOTE: Over firstname.lastname@example.org with any email address. And change email@example.com with the email address that will be used to receive email (use a valid email, so we know email has been entered or not).
If You Use Another SMTP Server
In principle, the configuration is the same, all you need to change is the
/ etc / postfix / sasl / passwd in order to match the SMTP server address, port, username and password
[mail.ispserver.com]: 587 username: password
And also change relayhost on file
relayhost = [mail.ispserver.com]: 587
Don't forget to create a hash db with orders
postmap / etc / postfix / sasl_passwd
And also restart Postfix
service postfix restart