First, you must gather the necessary information about your third party SMTP host. You need the following information:
- SMTP host
- SMTP host's port
- SMTP username
- SMTP password
- SMTP host's port
- SMTP username
- SMTP password
In my case, I use Mailrelay. And their SMTP-related information is posted in my account like the following:
SMTP access
This option allows you to activate the SMTP for your Mailrelay account.
Before activating the service, you will have to add the correct SPF record for your domain, you can find more information here.
Once the spf record is correct, click on "Activate".
If you need to send using SSL/TLS connection, use port 465. For more information, please contact us.
The SMTP service is active for your account.
SMTP Host my-domain.ip-zone.com
Port 465 (with SSL encryption) or 25/2525 (without SSL encryption)
SMTP Username my-domain
This option allows you to activate the SMTP for your Mailrelay account.
Before activating the service, you will have to add the correct SPF record for your domain, you can find more information here.
Once the spf record is correct, click on "Activate".
If you need to send using SSL/TLS connection, use port 465. For more information, please contact us.
The SMTP service is active for your account.
SMTP Host my-domain.ip-zone.com
Port 465 (with SSL encryption) or 25/2525 (without SSL encryption)
SMTP Username my-domain
Like what it says above, you must add the correct SPF record for your domain. Each third party SMTP host is different, and they will tell you how to add the correct SPF record. In my case, my SPF record looks like this:
SPF my-domain.com v=spf1 include:my-domain.ip-zone.com a mx -all
SPF my-domain.com v=spf2.0/pra include: my-domain.ip-zone.com a mx -all
TXT my-domain.com v=spf1 include:my-domain.ip-zone.com a mx -all
SPF my-domain.com v=spf2.0/pra include: my-domain.ip-zone.com a mx -all
TXT my-domain.com v=spf1 include:my-domain.ip-zone.com a mx -all
And there's a section below that allows me to set my SMTP password. Therefore, my information is the following:
- SMTP host = my-domain.ip-zone.com
- SMTP host's port = 25 (because I don't use SSL)
- SMTP username = my-domain
- SMTP password = ...this is a secret...
- SMTP host's port = 25 (because I don't use SSL)
- SMTP username = my-domain
- SMTP password = ...this is a secret...
There's one more step. You need to create a file with your username and password in it. Here are the steps:
1. Edit the /etc/postfix/sasl_passwd file. If the file does not exist, create it. Add the following lines to the file, replacing USERNAME and PASSWORD with your SMTP username and password.
[my-domain.ip-zone.com]:25 USERNAME:PASSWORD
Save and close the sasl_passwd file.
2. At a command prompt, issue the following command to create a hashmap database file containing your SMTP credentials.
sudo postmap hash:/etc/postfix/sasl_passwd
[my-domain.ip-zone.com]:25 USERNAME:PASSWORD
Save and close the sasl_passwd file.
2. At a command prompt, issue the following command to create a hashmap database file containing your SMTP credentials.
sudo postmap hash:/etc/postfix/sasl_passwd
Now you are ready to configure your program's email-related settings. You need to know which email program your code is using. In my case, I use PHP, and the email program I use is Postfix. Therefore I must configure Postfix to use the third party SMTP host by editing /etc/postfix/main.cf. The main lines in /etc/postfix/main.cf are as follows:
relayhost = [my-domain.ip-zone.com]:25
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd_mailrelay
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd_mailrelay
Save the changes and we are done! Try sending out an email from your PHP code and see if your recipient gets it! If the third party SMTP host is reliable, your email should NOT end up in the spam folder of the recipient's email box.
Questions? Let me know!