Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Tuesday, May 28, 2013

Configure Gmail SMTP Relay

SMTP stands for Simple Mail Transfer Protocol, lets you send email messages through your email account using your existing email service. This email service is subject to your interest. It could be any like: Gmail Relay, Snail Mail etc.

In this post we are going to configure Gmail Relay to send emails.


Install Postfix and other required packages.
yum install postfix
yum install mail*
yum install libsasl2-modules*
yum install cyrus-sasl-lib.x86_64 cyrus-sasl-lib.i686 -y
yum install cyrus-sasl-plain -y
  • Configure Postfix main configuration
    1. Open main configuration file in edit mode.
      vi /etc/postfix/main.cf
    2. Add these lines in main configuration file at the bottom:
      smtp_sasl_security_options =
      relayhost = [smtp.gmail.com]:587
      smtp_use_tls = yes
      smtp_tls_CAfile = /etc/postfix/cacert.pem
      smtp_sasl_auth_enable = yes
      smtp_sasl_password_maps = hash:/etc/postfix/sasl/passwd
      smtp_sasl_authentication_filter =
      
    3. Save and exit
  • Create /etc/postfix/sasl/passwd
    1. Create a directory sasl under /etc/postfix and create a file passwd with contents below:
      [smtp.gmail.com]:587  username@gmail.com:password
      Save and exit
    2. Change permission
      chmod 600 /etc/postfix/sasl/passwd
    3. Create lookup table via postmap
      postmap /etc/postfix/sasl/passwd
      Issuing that command will create passwd.db 
  • Generate your own CA certificate
    1. Change directory to /etc/pki/tls/certs
      cd /etc/pki/tls/certs
    2. Create a key and test certificate in one file
      make hostname.pem
      You will something like
      [root@ip-10-112-95-49]# make hostname.pem
      
      umask 77 ; \
      PEM1='/bin/mktemp /tmp/openssl.XXXXXX' ; \
      PEM2='/bin/mktemp /tmp/openssl.XXXXXX' ; \
      /usr/bin/openssl req -utf8 -newkey rsa:1024 -keyout $PEM1 -nodes -x509 -days 365 -out $PEM2 -set_serial 0 ; \
      cat $PEM1 >  hostname.pem ; \
      echo ""    >> hostname.pem ; \
      cat $PEM2 >> hostname.pem ; \
      rm -f $PEM1 $PEM2
      Generating a 1024 bit RSA private key
      ……………………….++++++
      …..++++++
      writing new private key to ‘/tmp/openssl.z12084'
      —– 
      You are about to be asked to enter information that will be incorporated 
      into your certificate request.
      What you are about to enter is what is called a Distinguished Name or a DN.
      There are quite a few fields but you can leave some blank
      For some fields there will be a default value,
      If you enter ‘.’, the field will be left blank.
      —–
      Country Name (2 letter code) [GB]:
      State or Province Name (full name) [Berkshire]:
      Locality Name (eg, city) [Newbury]:
      Organization Name (eg, company) [My Company Ltd]:
      Organizational Unit Name (eg, section) []:
      Common Name (eg, your name or your server's hostname) []:
      Email Address []:
      
    3. Fill-up the necessary information and copy the file on /etc/postfix as cacert.pem
      cp /etc/pki/tls/certs/hostname.pem /etc/postfix/cacert.pem 
  • Restart the postfix service
service postfix restart 
  • Inspect now your postfix logs to see if it can send out mails now to gmail servers
    A successful message states something like [[BR]]
    May  3 17:35:00 FLT postfix/smtp[28244]: 0ABB61CE32A: to=, relay=smtp.gmail.com[74.125.93.109]:587, delay=5, delays=0.41/0.02/2.7/1.8, dsn=2.0.0, status=sent (250 2.0.0 OK 1272879300 8sm8902550qwj.38)
    

Check Email functionality

To check that emails are working fine, use mail command.
mail -s subject recpientemailaddress
Example: mail -s "Email Notification" gaurav81083@gmail.com
.

Checking mail log

To check the mail logs, use tail command
tail -f /var/log/maillog

No comments:

Post a Comment