Configure Exim to use Gmail as the SMTP Server

Configuring Exim to use Gmail as the outgoing SMTP server is simple. This HOWTO will walk you through installing, configuring and routing email thru Gmail for exim.

The first step is to install exim4. Launch terminal and:

sudo apt-get install exim4

Run the following command to configure exim4:

sudo dpkg-reconfigure exim4-config

Set the following:

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: 127.0.0.1
Other destinations for which mail is accepted:  (default)
Visible domain name for local users: yourdomain.com
IP address or host name of the outgoing smarthost: smtp.gmail.com::587
Keep number of DNS-queries minimal (Dial-on-Demand)? No
Split configuration into small files? No

The exim4 SMTP server is now set to route emails thru Gmail. Now all we need to do is to tell exim4 the username and password we are going to use. To accomplish this create a text file called /etc/exim4/passwd.client. Update the file to read:

# password file used when the local exim is authenticating to a remote
# host as a client.
#
# see exim4_passwd_client(5) for more documentation
#
# Example:
### target.mail.server.example:login:password
gmail-smtp.l.google.com:you@gmail.com:password
*.google.com:you@gmail.com:password
smtp.gmail.com:you@gmail.com:password

Replace you@gmail.com:password with your login information.

Reload the exim4 server:

sudo /etc/init.d/exim4 reload

To test the configuration launch a terminal and type:

echo 'ok' | mail -s 'Gmail SMTP Relay Test' youremail @ domain.com

NOTE: the spaces in "youremail @ domain.com" are added to avoid Drupal converting the text to a linked email.

That is it!

Cheers.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

thanks

Thanks for the tip. This is a useful, partial work around to the problem of ISPs blocking port 25 and email from "consumer desktops," aka Windows botnet hosts. While people in the US still can't run useful servers as part of their internet service, they can at least use their machine in a general way to send mail. This can simplify small office setup. It's funny how Google can offer better Internet service than most ISPs without owning any wires.

Thanks!

Works well.

With this configuration,

With this configuration, every single outgoing mail, regardless of who sent it, will appear in the From field as "you@gmail.com".

Any way to have different gmail user/passwords sent, based on which From: or Sender: fields contain? Failing that, how about based on the user name?

Thanks,

--Ken

You raise a good point. The

You raise a good point. The only way I could make this work is my having all my emailer programs specify the "Reply-To:" header fields. This solves the issue when people click on the replay to button in their email client. There are still some issues that one must weight when using GMail to send messages:

  • The email will always appear to come from the specific gmail account
  • Bounce-backs will end up going back to the gmail account
  • There is a 100 email limit per day

Thanks for raising this issue. Here is another link you may find of interest: How to send e-mails from any address using Gmail's SMTP server.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h1> <h2> <h3> <h4> <h5> <h6> <pre> <hr>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
7 + 11 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.