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!

Comments

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

    ReplyDelete
  2. [...] These instructions have been updated for Ubuntu 8.10 HERE [...]

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

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

    ReplyDelete
  5. May be worth mentioning they also work fine on CentOS

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

    ReplyDelete
  7. May be worth mentioning they also work fine on CentOS

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

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

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


    on centos?

    ReplyDelete
  11. silly me didnt use sudo to create

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

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


    on centos?

    ReplyDelete
  14. silly me didnt use sudo to create

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

    ReplyDelete
  16. [...] I’ve been on Google mail hosting for a long time now and needed to configure my server to relay mail through it. Here’s a nice article that walks you through exactly what needs to be done to configure your sendmail MTA to relay through Gmail’s SMTP servers. Another similar post here. [...]

    ReplyDelete
  17. FYI just used this on 9.04 works flawlessly.

    ReplyDelete
  18. FYI just used this on 9.04 works flawlessly.

    ReplyDelete
  19. 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

    ReplyDelete
  20. 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

    ReplyDelete
  21. 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

    ReplyDelete
  22. 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

    ReplyDelete
  23. 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

    ReplyDelete
  24. 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

    ReplyDelete
  25. 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!

    ReplyDelete
  26. 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!

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

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

    ReplyDelete
  29. That was too easy :)

    Thanks

    ReplyDelete
  30. That was too easy :)

    Thanks

    ReplyDelete
  31. 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.

    ReplyDelete
  32. 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.

    ReplyDelete
  33. Who test this server, i how send a test mail ??

    ReplyDelete
  34. Who test this server, i how send a test mail ??

    ReplyDelete
  35. How do you send a test mail?

    ReplyDelete
  36. How do you send a test mail?

    ReplyDelete
  37. Thanks James. I found this really usefull.

    ReplyDelete
  38. Thanks James. I found this really usefull.

    ReplyDelete
  39. thanks james... this page is in my bookmarks... since long time

    ReplyDelete
  40. thanks james... this page is in my bookmarks... since long time

    ReplyDelete
  41. greetings,

    I'm testing this on Ubuntu 9.10, but it seems I can't make it work. Can you please tell me if this was tested on Ubuntu 9.10? My machine is updated :)

    ReplyDelete
  42. Its been tested on an up to date 9.04 as am skipping 9.10 on my server. Though cant' think of any major changes that would stop it working.

    ReplyDelete
  43. greetings,

    I'm testing this on Ubuntu 9.10, but it seems I can't make it work. Can you please tell me if this was tested on Ubuntu 9.10? My machine is updated :)

    ReplyDelete
  44. Its been tested on an up to date 9.04 as am skipping 9.10 on my server. Though cant' think of any major changes that would stop it working.

    ReplyDelete
  45. steven.m.murphy18 May 2010 at 10:53

    Yuck. I'm on centos 5.4; I took the sendmail.mc that is provided as a default for sendmail.
    All the suggested setup provided above, and the connection is refused by gmail.
    Using the -X option added on sendmail daemon startup, I see this in the log:

    13211 === CONNECT smtp.gmail.com
    13211 <<>> EHLO bromley.whatever.com
    13211 <<< 250-mx.google.com at your service, [174.143.244.25]
    13211 <<< 250-SIZE 35651584
    13211 <<< 250-8BITMIME
    13211 <<< 250-STARTTLS
    13211 <<>> STARTTLS
    13211 <<>> EHLO bromley.whatever.com
    13211 <<< 250-mx.google.com at your service, [174.143.244.25]
    13211 <<< 250-SIZE 35651584
    13211 <<< 250-8BITMIME
    13211 <<< 250-AUTH LOGIN PLAIN XOAUTH
    13211 <<>> MAIL From: SIZE=639
    13211 <<< 530-5.5.1 Authentication Required. Learn more at
    13211 <<>> This is a MIME-encapsulated message
    13211 >>>
    ...

    I've been trying all sorts of tweaks, I get the same stuff over and over. What does it take to get the authentication sent to gmail? Any suggestions?

    ReplyDelete
  46. steven.m.murphy18 May 2010 at 17:53

    Yuck. I'm on centos 5.4; I took the sendmail.mc that is provided as a default for sendmail.
    All the suggested setup provided above, and the connection is refused by gmail.
    Using the -X option added on sendmail daemon startup, I see this in the log:

    13211 === CONNECT smtp.gmail.com
    13211 <<>> EHLO bromley.whatever.com
    13211 <<< 250-mx.google.com at your service, [174.143.244.25]
    13211 <<< 250-SIZE 35651584
    13211 <<< 250-8BITMIME
    13211 <<< 250-STARTTLS
    13211 <<>> STARTTLS
    13211 <<>> EHLO bromley.whatever.com
    13211 <<< 250-mx.google.com at your service, [174.143.244.25]
    13211 <<< 250-SIZE 35651584
    13211 <<< 250-8BITMIME
    13211 <<< 250-AUTH LOGIN PLAIN XOAUTH
    13211 <<>> MAIL From: SIZE=639
    13211 <<< 530-5.5.1 Authentication Required. Learn more at
    13211 <<>> This is a MIME-encapsulated message
    13211 >>>
    ...

    I've been trying all sorts of tweaks, I get the same stuff over and over. What does it take to get the authentication sent to gmail? Any suggestions?

    ReplyDelete
  47. This may work for a normal gmail account but it is not working with my Google apps mail account. It requires an SSL connection on port 465.

    Please help.

    Thanks.

    ReplyDelete
  48. Though im a heavy google apps user i have never tried that, should note that I have tried my solution on 10.04 with no luck.

    However Im currently using Sendmail installed on 10.04 with zero config tweaks to sendmail to sendmail. The only change i have made is to edit the hosts file to reflect my google apps domain. As Google will reject email that are sent from localhost.localdomain (quite rightly). This works on its own. However I would recommend then setting up your SPF record to include your sendmail server.

    Hope that helps.

    ReplyDelete
  49. This may work for a normal gmail account but it is not working with my Google apps mail account. It requires an SSL connection on port 465.

    Please help.

    Thanks.

    ReplyDelete
  50. Though im a heavy google apps user i have never tried that, should note that I have tried my solution on 10.04 with no luck.

    However Im currently using Sendmail installed on 10.04 with zero config tweaks to sendmail to sendmail. The only change i have made is to edit the hosts file to reflect my google apps domain. As Google will reject email that are sent from localhost.localdomain (quite rightly). This works on its own. However I would recommend then setting up your SPF record to include your sendmail server.

    Hope that helps.

    ReplyDelete
  51. [...] Using Gmail as a Sendmail Relay | James Lloyd – 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.<br /> <br /> 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. [...]

    ReplyDelete
  52. Thanks, it works on Ubuntu 10.10 :)

    ReplyDelete
  53. How do you send a test mail?

    ReplyDelete
  54. echo 'this is a test'| mail -s test_email user@domain

    ReplyDelete
  55. [...] from two sites: AppGirl: “Configuring Sendmail to relay through Gmail SMTP” and James Lloyd: “Using Gmail as a Sendmail Relay”. Open a terminal and [...]

    ReplyDelete
  56. @9cb73f675096dc39f30821500c8b6c31:disqus ... i am using Ubuntu 10.04 LTS .... will it work in it ..??

    ReplyDelete
  57. @9cb73f675096dc39f30821500c8b6c31:disqus ... `m using Ubuntu 10.04 LTS ... will it work in it ..?

    ReplyDelete
  58. help please :(

    echo 'this is a test'| mail -s magdaelenamary@gmail.com magdaelenamary@gmail.com
    The program 'mail' can be found in the following packages:
     * heirloom-mailx
     * mailutils
    Try: sudo apt-get install

    ReplyDelete

Post a Comment

Popular posts from this blog

The Beer Belly

T-Rextasy