Home > Techy Stuff > Using Gmail as a Sendmail Relay

Using Gmail as a Sendmail Relay

The revenge this time its personal!

K I just setup sendmail to relay using gmail again,  thought I better post what I have done as my original now out of date post is still getting quite a lot of views.

This is based on my Ubuntu 8.10 Server ( 2.6.27-11-server) all patched up todays date and then I did the below.

First off make sure you can actually resolve gmail.com, working ? good.

sudo apt-get install sendmail
sudo cp /etc/mail/sendmail.mc /etc/mail/sendmail.mc.orig
sudo vi /etc/mail/sendmail.mc

Add the following to the bottom of your virgin sendmail.mc (shift+g to get to end of file):

define(`SMART_HOST',`smtp.gmail.com')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl
define(`CERT_DIR', `MAIL_SETTINGS_DIR`'certs')
define(`confCACERT_PATH', `CERT_DIR')
define(`confCACERT', `CERT_DIR/CAcert.pem')
define(`confSERVER_CERT', `CERT_DIR/mycert.pem')
define(`confSERVER_KEY', `CERT_DIR/mykey.pem')
define(`confCLIENT_CERT', `CERT_DIR/mycert.pem')
define(`confCLIENT_KEY', `CERT_DIR/mykey.pem')

Save the file.

sudo mkdir /etc/mail/auth
sudo vi /etc/mail/auth/client-info

Add the following line to the new client-info file replacing the text between the greater than and less than signs (did I need to spell that out ?):

AuthInfo:smtp.gmail.com "U:root" "I:<YOUR GMAIL USERNAME HERE>@gmail.com" "P:<YOU GMAIL PASSWORD HERE>"

Save the file.

makemap hash client-info < client-info
chmod 700 /etc/mail/auth
chmod 600 /etc/mail/auth/*
mkdir /etc/mail/certs
cd /etc/mail/certs
openssl dsaparam 1024 -out dsa1024 -out dsa1024.pem
openssl req -x509 -nodes -days 3650 -newkey dsa:dsa1024.pem -out /etc/mail/certs/mycert.pem -keyout /etc/mail/certs/mykey.pem
ln -s /etc/mail/certs/mycert.pem /etc/mail/certs/CAcert.pem
openssl req -x509 -new -days 3650 -key /etc/mail/certs/mykey.pem -out /etc/mail/certs/mycert.pem
chmod 700 /etc/mail/certs
chmod 600 /etc/mail/certs/*
cd /etc/mail
make
/etc/init.d/sendmail reload

Bish Bosh!

Categories: Techy Stuff Tags: , ,
  1. Jd
    April 7th, 2009 at 20:28 | #1

    You are amazing. I have been trying this for days. Thank you.

  2. florian
    April 23rd, 2009 at 08:40 | #2

    Thank you very much, that was exactly what I needed and it saved a lot of time (I guess). Cheers!

  3. April 23rd, 2009 at 08:41 | #3

    May be worth mentioning they also work fine on CentOS

  4. April 30th, 2009 at 11:36 | #4

    This works on Ubuntu 8.04.2 as well. Thanks for posting this, it was a big help.

  5. mike
    September 24th, 2009 at 04:15 | #5

    [root@pbx-xen auth]# makemap hash client-info < client-info
    makemap: error opening type hash map client-info: Permission denied

    on centos?

  6. mike
    September 24th, 2009 at 04:19 | #6

    silly me didnt use sudo to create

  7. mike
    September 24th, 2009 at 04:28 | #7

    so i sendmail and it still uses localhost etc, it doesnt use smtp settings

  8. October 30th, 2009 at 05:21 | #8

    FYI just used this on 9.04 works flawlessly.

  9. Someguy
    November 5th, 2009 at 20:36 | #9

    Thanks for the tips. For Fedora users, the additional configuration belongs right around the existing “SMART_HOST” config in the sendmail.mc. Then, after installing sendmail-cf package, you issue:

    make sendmail.cf -C /etc/mail
    /etc/init.d/sendmail restart

  10. Ian Pilcher
    November 13th, 2009 at 20:20 | #10

    I found that this works just fine without doing any of the client certificate stuff. All I had to do (on Fedora 11) was:

    * Add the first 3 lines to sendmail.mc
    * Create /etc/mail/auth/client-info with the given contents
    * Set the permissions of /etc/mail/auth and /etc/mail/auth/client-info
    * Run the makemap command
    * cd /etc/mail && make
    * service sendmail restart

  11. Phillip
    November 19th, 2009 at 08:58 | #11

    Why does need cert?
    I can send with and without cert. Message is sending without problem except..

    In both ways I got answer:

    STARTTLS=client… verify=FAIL

  12. Bear
    December 6th, 2009 at 05:12 | #12

    You rock! You are ace! Pulled out all my hair trying to get this, and you were spot on. I am naming all my children after you, because you were named before them. Schweet!

  13. December 7th, 2009 at 06:00 | #13

    Thank you very much James!!
    Short, easy and it works!

  14. Joe Black
    December 7th, 2009 at 20:46 | #14

    That was too easy :)

    Thanks

  15. Zaphod
    December 9th, 2009 at 01:01 | #15

    Danke!

  16. Andrei
    January 12th, 2010 at 05:16 | #16

    Thank you! This works in Slackware 13 with some minor modifications:

    - Edit ‘/usr/share/sendmail/cf/cf/sendmail-slackware.mc’ instead of ‘/etc/mail/sendmail.mc’ (be sure to back up the original)
    - Add the needed lines – make sure the FEATURE line appears ahead of any MAILER lines in the file.
    - Rather than running ‘make’ in the ‘/etc/mail’ dir, run `m4 sendmail-slackware.mc > /etc/mail/sendmail.cf’ in the ‘/usr/share/sendmail/cf/cf/’ directory as root
    - Once done, restart sendmail by running ‘/etc/rc.d/rc.sendmail restart’

    The other steps are the same.

  17. bit
    February 12th, 2010 at 09:42 | #17

    Who test this server, i how send a test mail ??

  18. Ohw
    February 18th, 2010 at 10:12 | #18

    How do you send a test mail?

  19. Nacho
    February 22nd, 2010 at 07:42 | #19

    Thanks James. I found this really usefull.

  1. April 8th, 2009 at 01:31 | #1
  2. September 28th, 2009 at 14:55 | #2