Configure Exim to send emails with Gmail

We will see how to configure Exim4 to send system emails with Gmail. This will ensure that your emails sent with your CRON are correctly routed and do not end up in spam.

Let's install Exim4

apt-get install exim4


dpkg-reconfigure exim4-config

Choose: mail sent by smarthost; no local mail


Then answer the questions as follows:

System mail name: YOUR_HOSTNAME

IP-addresses to listen on for incoming SMTP connections: ; ::1

Other destinations for which mail is accepted: <BLANK>

Visible domain name for local users: <BLANK>

IP address or host name of the outgoing smarthost:

Keep number of DNS-queries minimal (Dial-on-Demand)? No

Split configuration into small files? No

Root and postmaster mail recipient: <BLANK>

Open and edit the file: /etc/exim4/exim4.conf.template

Search for:

.ifdef DCconfig_smarthost DCconfig_satellite

And add these lines just after:

    driver = manualroute
    domains = ! +local_domains
    transport = gmail_smtp
    route_list = *

Delete all other smarthost blocks containing:

domains = ! +local_domains

Comment them out with a # at the beginning of the line


Search for the authenticators with the occurrence:

begin authenticators

And add these lines:

    driver = plaintext
    public_name = LOGIN
    client_send = : : VOTRE_PASS_GMAIL

Delete all other blocks that contain:

public_name = LOGIN

You can also just rename them like this:

  driver = plaintext
  public_name = LOGIN_BACK

This avoids having a naming conflict.

Then search for:


And add these lines:

    driver = smtp
    port = 587
    hosts_require_auth = $host_address
    hosts_require_tls = $host_address

Close and save your configuration file: /etc/exim4/exim4.conf.template

We reload the configuration file:


And we restart the service:

/etc/init.d/exim4 restart

We can test our email sending:

echo 'Test' | mail -s 'Message test' VOTRE_EMAIL@ADDRESSE