Debian - Configure Sendmail to use your Gmail account



If you are running a Debian server, you must be running some automated processes like database dump, log cleaning, data backup, …

When processing these batch treatments, it can be very convenient to get some completion reports sent by email.

Under debian, you can send mails thru command line with the help of sendmail and exim4 as a mail transfert agent. But you previously need to configure them to use an official smtp server.

This article will explain how to configure your Debian Wheezy server to be able to send emails from command line by using the smtp server provided with your Gmail account.

Configuration is given for a Gmail account, but it can obviously be adapted to any other smtp provider.

This article has been tested on a freshly installed Amd64 Debian Wheezy.

1. Configure Exim4

Exim4 is installed by default, but it needs to be reconfigured to setup a Gmail server configuration :

# dpkg-reconfigure exim4-config

You will ge thru a setup procedure. Make sure to set it up as follow :

Option Choice 
 Configuration type  mail sent by smarthost; received via SMTP or fetchmail
 System mail name  Any hostname like (localhost refused)
 IP-addresses to listen on for incoming SMTP connections (to refuse external connections)
Other destinations for which mail is accepted leave empty
Machines to relay mail for leave empty
IP address or host name of the outgoing smarthost
Hide local mail name in outgoing mail ? no
Keep number of DNS-queries minimal (Dial-on-Demand) ? no
Delivery method for local mail mbox format in /var/mail/
Split configuration into small files ? yes


2. Declare your Gmail account

As Gmail is using authentification on its smtp servers, you need to declare your account:password for the gmail servers.

This is done in the file /etc/exim4/passwd.client where you have to declare any server gmail can use.


# 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

As Exim is quite touchy about the rights of its password files, it's better to explicitly setup proper ownership and permissions.

# chown Debian-exim:root /etc/exim4/passwd.client
# chmod 640 /etc/exim4/passwd.client

Finally, we need to reload exim4 for the setup to be used.

We will also configure it to do a delivery attempt for every message, whether frozen or not (-qff option).

# update-exim4.conf
# invoke-rc.d exim4 restart
# exim4 -qff

3. Send your first mail

Everything is now ready to send your first command line email.

To send your first mail, you now need to prepare the email body in a text file.

This email body should respect a specific structure that will provide :

  1. the Recipient (to:)
  2. the Sender (from:)
  3. the Subject (subject:)
  4. the mail text


to : This email address is being protected from spambots. You need JavaScript enabled to view it.
from : Your server name
subject : Test mail

This is the first mail sent by my server's sendmail !

Now that the mail body is ready, you just need to pass it to sendmail with the -t option for it to send the mail :

# cat /root/mail-body.txt | sendmail -t

You should receive a mail like this one :



Hope it helps.

Signature Technoblog

This article is published "as is", without any warranty that it will work for your specific need.
If you think this article needs some complement, or simply if you think it saved you lots of time & trouble,
just let me know at This email address is being protected from spambots. You need JavaScript enabled to view it.. Cheers !

icon linux icon debian icon apache icon mysql icon php icon piwik icon googleplus