Ubuntu Server – Configuring Exim4 to Send Email Via Gmail


I am in the midst of trying to get Kaltura to work on Ubuntu 10.4 but am experiencing an error that is a bit of a show stopper.

The good news is that I needed to configure Exim4 to send email via Gmail – and that is what this post is about.

First install Exim4:

sudo apt-get install exim4

Configure Exim with the following command:

sudo dpkg-reconfigure exim4-config

Press the down-arrow key to select mail sent by smarthost; received via SMTP or fetchmail then press Tab, followed by Enter:

Enter a system mail name – this might be your company-name.com or a dummy domain name like I used below:

Next we specify an IP address to listen for incoming SMTP connections. This field was already completed for me with the value 127.0.0.1 ; ::1

The next screen was auto-completed with my host-name (which I had previously edited in /etc/hosts). The guide that I followed said to leave this blank but I left it as it was:

I left the Machines to relay for blank:

Select No don’t Hide local mail name in outgoing mail:

Select No to Keep number of DNS-queries minimal (Dial on-Demand):

For Delivery method for local mail choose mbox format in /var/mail/:

For Split configuration into small files select No:

Now we need to make several changes to the configuration to Exim4 in the file etc/exim4/exim4.conf.template:

sudo nano etc/exim4/exim4.conf.template

Find the line .ifdef DCconfig_smarthost DCconfig_satellite and add the following in that section (you can press Ctrl + W to search in nano):

send_via_gmail:
    driver = manualroute
    domains = ! +local_domains
    transport = gmail_smtp
    route_list = * smtp.gmail.com

The guide that I followed said to remove any other smarthost defined with domains = ! +local_domains in /etc/exim4/exim4.conf.template but I did not find any.

Next find the comment begin authenticators section and add the following:

gmail_login:
    driver = plaintext
    public_name = LOGIN
    client_send = : yourname@gmail.com : YourGmailPassword

Find the comment transport/30_exim4-config_remote_smtp_smarthost and add the following:

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

Finally comment out the login section of /etc/exim4/exim4.conf.template:

#Commented out so that Gmail’s Public_name can equal “LOGIN”
#login:
# driver = plaintext
# public_name = LOGIN
#.ifndef AUTH_CLIENT_ALLOW_NOTLS_PASSWORDS
# Return empty string if not non-TLS AND looking up $host in passwd-file
# yields a non-empty string; fail otherwise.
# client_send = “<; ${if and{\
# {!eq{$tls_cipher}{}}\
# {!eq{PASSWDLINE}{}}\
# }\
# {}fail}\
# ; ${extract{1}{::}{PASSWDLINE}}\
# ; ${sg{PASSWDLINE}{\\N([^:]+:)(.*)\\N}{\\$2}}”
#.else
# Return empty string if looking up $host in passwd-file yields a
# non-empty string; fail otherwise.
# client_send = “<; ${if !eq{PASSWDLINE}{}\
# {}fail}\
# ; ${extract{1}{::}{PASSWDLINE}}\
# ; ${sg{PASSWDLINE}{\\N([^:]+:)(.*)\\N}{\\$2}}”
#.endif
#####################################################
### end auth/30_exim4-config_examples
#####################################################

Press Ctrl + O and then Enter to save and then Ctrl + X to save the file and exit nano.

Update Exim4 with the following command:

Run update-exim4.conf

Restart Exim4:

 /etc/init.d/exim4 restart

Finally test your configuration by sending an email via the command line:

mail user@example.com

Type a Subject and then press Enter.

Type a message and then press Enter.

Type a single . (dot) and then press Enter.

Press Enter again for a blank CC address.

Within a few minutes you should receive an email at the specified email address.

Sources:

http://www.manu-j.com/blog/wordpress-exim4-ubuntu-gmail-smtp/75/

http://basskozz.wordpress.com/2008/12/07/how-to-setup-a-raid5-software-mdadm-array-w-email-notifications-via-gmail-the-easy-way/ 

Advertisements

4 thoughts on “Ubuntu Server – Configuring Exim4 to Send Email Via Gmail

  1. “gmail_login:
    driver = plaintext
    public_name = LOGIN
    client_send = : yourname@gmail.com : YourGmailPassword”
    – I don’t wanna see my google password anywhere… – And plaintext?
    – Isn’t it insecure a little bit?

    1. I only planned to use a set up like this for sending alerts or other admin related things and I set up a new gmail account for this purpose. This is a test (not production) setup.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s