Syed Jahanzaib – Personal Blog to Share Knowledge !

December 27, 2012

Howto configure GMAIL as SENDMAIL RELAY :D (Also can be used with RM to send Email Notifications)

Filed under: Linux Related, Radius Manager — Tags: , , — Syed Jahanzaib / Pinochio~:) @ 3:01 PM

gmail-logo

If you want to use GMAIL as your sendmail relay server, Use the below configuration.

{I required it to send DMASOFTLAB RADIUS MANAGER Email notifications to all users regarding there service status, account expiry, renewal , various alerts and other info. that’s why I wrote this guide, it maybe useful for others too . . Syed Jahanzaib }

OS Used: Ubuntu 10.4 / 12.4

First install Sendmail and its utilities.


apt-get install sendmail mailutils

Now configure signed SSL certificates

 mkdir /etc/mail/certs
 chmod 700 /etc/mail/certs
 cd /etc/mail/certs


openssl dsaparam 1024 -out dsa1024 -out dsa1024.pem

(It will ask you various questiosn , just enter them accordingly, like country code, for Pakistan its PK, and other information you have)


openssl req -x509 -nodes -days 3650 -newkey dsa:dsa1024.pem -out /etc/mail/certs/mycert.pem -keyout /etc/mail/certs/mykey.pem

(It will ask you various questions , just enter them accordingly, like country code, for Pakistan its PK, and other information you have)


openssl req -x509 -new -days 3650 -key /etc/mail/certs/mykey.pem -out /etc/mail/certs/mycert.pem

 


ln -s /etc/mail/certs/mycert.pem /etc/mail/certs/CAcert.pem
 chmod 600 /etc/mail/certs/*
 cd ..

Now configure gmail SMTP authentication information, This file may be blank, just paste the text showed in code box.
nanoย  /etc/mail/authinfo
AuthInfo:smtp.gmail.com "U:root" "I:USERNAME@gmail.com" "P:PASSWORD" AuthInfo: "U:root" "I:USERNAME@gmail.com" "P:PASSWORD"

Save & Exit & issue below command

makemap hash /etc/mail/authinfo < /etc/mail/authinfo
Now Add the following configurations at the bottom of sendmail.mc file
nano /etc/mail/sendmail.mc

dnl #
dnl # SSL Settings
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')
dnl #
dnl # GMAIL FORWARDING
define(`SMART_HOST',`[smtp.gmail.com]')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
define(`confAUTH_OPTIONS', `A p')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash -o /etc/mail/authinfo.db')dnl

Now rebuild sendmail config and start the service ๐Ÿ˜€

make -C /etc/mail
service sendmail restart

 

Test the setup ๐Ÿ˜‰

Use the below command to test the local smtp .

– – – – -??

Regard’s
Syed Jahanzaib