How to configure Exim to use SendGrid to send mail

I continue my series of articles about email services until the inspiration from the recently solved problems wears off.

I have already described how to configure PostFix to send mail via MailGun.

This article will discuss how to configure Exim to use the SendGrid mail delivery service.

The description of setting up different mail services on different mail daemons coincides very well.

I have a server with WHM + Exim panel. I signed up for a free account with SendGrid.

First, in the WHM panel, find Exim Configuration Manager Screenshot from 2016-03-01 13:59:38

Go to the Advanced Editor tab and look for the Section: AUTH section. In the text field you need to insert information for authorization in sendgrid:

sendgrid_login:
   driver = plaintext
   public_name = LOGIN
   client_send = : [email protected] : %password%

Next we look for the section Section: ROUTERSTART. We insert the following into it:

send_via_sendgrid:
   driver=manualroute
   domains = ! +local_domains
   transport = sendgrid_smtp
   route_list = "* smtp.sendgrid.net::587 byname"
   host_find_failed = defer
   no_more

All that remains is to specify the transport. To do this, find Section: TRANSPORTSTART and enter the following in the text field:

sendgrid_smtp:
   driver = smtp
   hosts = smtp.sendgrid.net
   hosts_require_auth = smtp.sendgrid.net
   hosts_require_tls = smtp.sendgrid.net

If you want to use DKIM then TRANSPORTSTART is exactly the place to add the configuration:

DKIM_CANON = relaxed
DKIM_SELECTOR = key1
DKIM_DOMAIN = example.com
DKIM_FILE = /etc/ssl/private/example.com-private.pem