Due to the popularity of Gmail, Google Apps, Outlook.com, Yahoo! Mail & a myriad of other providers, many cloud-server users mistakenly fail to install a mail server, initially. However, humans are not the only ones that send electronic mail. In fact, many Linux server applications also need to send emails.
What is SMTP?
Simple Mail Transfer Protocol (SMTP) is a widely supported standard for sending an email. Most development frameworks support SMTP without the need for any extra libraries, making SMTP the quickest way to start sending transactional emails from your web application.
Sending emails using SMTP.
Setting up your web application to send emails using SMTP couldn’t be easier. It’s as simple as copying some credentials into a config file and you’re ready to send.
Why Exim 4?
Exim4 is a Message Transfer Agent (MTA) developed at the University of Cambridge for use on Unix systems connected to the Internet. Exim can be installed in place of Sendmail, there is a great deal of flexibility in the way mail can be routed, and there are extensive facilities for checking incoming mail.
- Sendmail Compactability
- Huge supportive community
- cPanel support
- Very flexible in configuration
- Monolithic architecture
- Slow queuing operation speed
Exim is like a framework with its own application language to perform complex configurations. It has an advanced multi-step mail processing logic that is suitable for complex cases.
Set Your SmartHost
Before configuring Exim as SMTP-relay, we have to make sure Exim is installed on your CloudStick powered server. Exim 4 is also installed during the installation of CloudStick. We can check Exim installed on CloudStick using the command,
dpkg -l | grep exim
Now let’s take a backup of the Exim4 conf file we can use it later if anything goes wrong, using the command
cp -r /etc/exim4/exim4.conf.template /etc/exim4/exim4.conf.template-bak
Let’s open the Exim4 configuration file on any editor, here I am using vim.
Scroll down in the Editor until you reach the ‘begin authenticators’. Enter the following, so that it matches the screenshot below. Note, you will want to use your Server API Token from Postmark where it says ‘YourServerAPITokenHere’.
driver = plaintext
public_name = LOGIN
client_send = : YourServerAPITokenHere : YourServerAPITokenHere
Scroll down further and under ‘begin routers ’add the following
driver = manualroute
domains = ! +local_domains
ignore_target_hosts = 127.0.0.0/8
transport = auth_relay
route_list = *
“route_list = *” can be varied depending on your provider. For example, if your provider is mailjet, then,
route_list = * in.mailjet.com:587
In case of the provider is postmark then,
route_list = * smtp.postmarkapp.com
Under ‘begin transports’
driver = smtpport = 587
hosts_require_auth = $host_address
hosts_require_tls = $host_address
Save file and exit from the editor and restart Exim service by using command
systemctl restart exim4.service
Your Exim configuration will be regenerated again and restarted with the configuration changes you made.
You can now send a test email from your server. As an example,
$ mail -s “Exim Test” [email protected] < /dev/null
If you send it to a legitimate email address, the email will appear in the inbox as well.