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!
You are amazing. I have been trying this for days. Thank you.
ReplyDelete[...] These instructions have been updated for Ubuntu 8.10 HERE [...]
ReplyDeleteYou are amazing. I have been trying this for days. Thank you.
ReplyDeleteThank you very much, that was exactly what I needed and it saved a lot of time (I guess). Cheers!
ReplyDeleteMay be worth mentioning they also work fine on CentOS
ReplyDeleteThank you very much, that was exactly what I needed and it saved a lot of time (I guess). Cheers!
ReplyDeleteMay be worth mentioning they also work fine on CentOS
ReplyDeleteThis works on Ubuntu 8.04.2 as well. Thanks for posting this, it was a big help.
ReplyDeleteThis works on Ubuntu 8.04.2 as well. Thanks for posting this, it was a big help.
ReplyDelete[root@pbx-xen auth]# makemap hash client-info < client-info
ReplyDeletemakemap: error opening type hash map client-info: Permission denied
on centos?
silly me didnt use sudo to create
ReplyDeleteso i sendmail and it still uses localhost etc, it doesnt use smtp settings
ReplyDelete[root@pbx-xen auth]# makemap hash client-info < client-info
ReplyDeletemakemap: error opening type hash map client-info: Permission denied
on centos?
silly me didnt use sudo to create
ReplyDeleteso i sendmail and it still uses localhost etc, it doesnt use smtp settings
ReplyDelete[...] 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. [...]
ReplyDeleteFYI just used this on 9.04 works flawlessly.
ReplyDeleteFYI just used this on 9.04 works flawlessly.
ReplyDeleteThanks 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:
ReplyDeletemake sendmail.cf -C /etc/mail
/etc/init.d/sendmail restart
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:
ReplyDeletemake sendmail.cf -C /etc/mail
/etc/init.d/sendmail restart
I found that this works just fine without doing any of the client certificate stuff. All I had to do (on Fedora 11) was:
ReplyDelete* 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
I found that this works just fine without doing any of the client certificate stuff. All I had to do (on Fedora 11) was:
ReplyDelete* 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
Why does need cert?
ReplyDeleteI can send with and without cert. Message is sending without problem except..
In both ways I got answer:
STARTTLS=client... verify=FAIL
Why does need cert?
ReplyDeleteI can send with and without cert. Message is sending without problem except..
In both ways I got answer:
STARTTLS=client... verify=FAIL
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!
ReplyDeleteYou 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!
ReplyDeleteThank you very much James!!
ReplyDeleteShort, easy and it works!
Thank you very much James!!
ReplyDeleteShort, easy and it works!
That was too easy :)
ReplyDeleteThanks
That was too easy :)
ReplyDeleteThanks
Danke!
ReplyDeleteDanke!
ReplyDeleteThank you! This works in Slackware 13 with some minor modifications:
ReplyDelete- 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.
Thank you! This works in Slackware 13 with some minor modifications:
ReplyDelete- 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.
Who test this server, i how send a test mail ??
ReplyDeleteWho test this server, i how send a test mail ??
ReplyDeleteHow do you send a test mail?
ReplyDeleteHow do you send a test mail?
ReplyDeleteThanks James. I found this really usefull.
ReplyDeleteThanks James. I found this really usefull.
ReplyDeletethanks james... this page is in my bookmarks... since long time
ReplyDeletethanks james... this page is in my bookmarks... since long time
ReplyDeletegreetings,
ReplyDeleteI'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 :)
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.
ReplyDeletegreetings,
ReplyDeleteI'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 :)
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.
ReplyDeleteYuck. I'm on centos 5.4; I took the sendmail.mc that is provided as a default for sendmail.
ReplyDeleteAll 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?
Yuck. I'm on centos 5.4; I took the sendmail.mc that is provided as a default for sendmail.
ReplyDeleteAll 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?
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.
ReplyDeletePlease help.
Thanks.
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.
ReplyDeleteHowever 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.
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.
ReplyDeletePlease help.
Thanks.
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.
ReplyDeleteHowever 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.
[...] 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. [...]
ReplyDeleteThanks, it works on Ubuntu 10.10 :)
ReplyDeleteHow do you send a test mail?
ReplyDeleteecho 'this is a test'| mail -s test_email user@domain
ReplyDelete[...] 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@9cb73f675096dc39f30821500c8b6c31:disqus ... i am using Ubuntu 10.04 LTS .... will it work in it ..??
ReplyDelete@9cb73f675096dc39f30821500c8b6c31:disqus ... `m using Ubuntu 10.04 LTS ... will it work in it ..?
ReplyDeletehelp please :(
ReplyDeleteecho '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