Setup exim4 to use Gmail in Ubuntu

Alright, we're now going to configure exim4 to use our Gmail account as SMTP Server.

In fact it's easier than how it sounds 😉

Install exim4

First of all install the following packages in this exact same order. Otherwise it could fail.

sudo apt-get install exim4-base exim4-config sudo apt-get install exim4-daemon-light sudo dpkg-reconfigure exim4-config
Code language: JavaScript (javascript)

The setup will be prompted. Configure as follows

The last command should have prompted a configuration screen. Configure it like this:

  • General type of mail configuration: mail sent by smarthost; no local mail
  • System mail name: (default)
  • IP-addresses to listen on for incoming SMTP connections:
  • Other destinations for which mail is accepted: (default)
  • Visible domain name for local users:
  • 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

Here's the same configuration but through screenshots. You can skip this and go to the next step if you want.

Create a file

We're now going to create the file with our Google Account credentials.

sudo touch /etc/exim4/passwd.client

Add the following lines and save the file

Change with your e-mail and password. *

Are you using 2 factor authentication?

If so, you can not use your regular Gmail password, you need an "App Password".

Go here: then generate a new App password. Use the new generated password in the /etc/exim4/passwd.client file.

Reload exim4

sudo /etc/init.d/exim4 reload

That's all !

You should be able to send e-mails using PHP for example:

About Ricard Torres

Senior Front-end Software Engineer at Netcentric, from Barcelona, Haidong Gumdo Instructor (korean martial art of the sword), street photographer, travel lover, TV addict, Boston Red Sox fan, and privacy advocate.

@ricard_dev @ricard_dev

📝 Blog 🎙 Podcast

Leave a Reply

Add <code> Some Code </code> if you need to.