Skip to main content

Configure Postfix to use Gmail in RHEL/CentOS



Relaying to Gmail via smtp.gmail.com can be accomplished by configuring your Postfix with SASL authentication and TLS encryption.
The common errors you will encounter if sending from your postfix mail server failing to gmail.com domain but works in other domains are:
@/var/log/maillog

-Must issue a STARTTLS command first
-certificate verification failed for gmail.com:unable to get local issuer certificate
-Authentication Required. Learn more at 530 5.5.1 http://mail.google.com/support/bin/answer.py?

How to fix?
Assuming you already installed Postfix and everything works fine except sending to gmail smtps, here are the steps to follow:
1. Configure Postfix main configuration
a.vi /etc/postfix/main.cf
b. Add these lines:
smtp_sasl_security_options = noanonymous

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

c. Save and exit
2. Create /etc/postfix/sasl/passwd
a. 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
b. Change permission

#chmod 600 /etc/postfix/sasl/passwd
c. Create lookup table via postmap

#postmap /etc/postfix/sasl/passwd
Issuing that command will create passwd.db
3. Generate your own CA certificate
a. Change directory to /etc/pki/tls/certs
#cd /etc/pki/tls/certs
b.Create a key and test certificate in one file
#make hostname.pem
You will something like
[root@FLT certs]# 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 []:

c. 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
4. Restart the postfix service
#service postfix restart

5. Inspect now your postfix logs to see if it can send out mails now to gmail servers
A successful message states something like

May  3 17:35:00 FLT postfix/smtp[28244]: 0ABB61CE32A: to=<linuxtechtips-tutorials@gmail.com>, 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)


Comments

Popular posts from this blog

CentOS / Redhat : Configure CentOS as a Software Router with two interfaces

Linux can be easily configured to share an internet connection using iptables. All you need to have is, two network interface cards as follows: a) Your internal (LAN) network connected via eth0 with static ip address 192.168.0.1 b) Your external WAN) network is connected via eth1 with static ip address 10.10.10.1  ( public IP provided by ISP ) Please note that interface eth1 may have public IP address or IP assigned by ISP. eth1 may be connected to a dedicated DSL / ADSL / WAN / Cable router: Step # 1: Enable Packet Forwarding Login as the root user. Open /etc/sysctl.conf file # vi /etc/sysctl.conf Add the following line to enable packet forwarding for IPv4: net.ipv4.conf.default.forwarding=1 Save and close the file. Restart networking: # service network restart Step # 2: Enable IP masquerading In Linux networking, Network Address Translation (NAT) or Network Masquerading (IP Masquerading) is a technique of transceivin

Virtual Box and Alt/Tab Keys

I use virtual box for all my testing activities. It comes too often that I have a virtual box VM window open & I want to switch to my host machine to see some stuff like tutorials etc.. If you press the alt+tab combination it just works inside the VM & doesn't switches to host machine. In these scenarios you can press the host key once ( not hold it ) & then whatever you press goes to host machine. So in general where host key is the default Right Ctrl, just press Right Ctrl once & now press the alt+tab & it will switch you out to host machine. This is really helpful when you have the VM windows open or you're working on seamless mode. Hope it help others too.

Set date and time in Linux

There are few ways to set the date and time on Linux command line. In order to do this, you must login as root and execute the following methods as follow: For you to remember the syntax, issue the command “date” first [root@linuxtechtips ~]# date Mon Aug 20 18:30:29 SGT 2012 Let say you want to change it to Sept 6, 2012, 3pm, just follow the pattern above [root@linuxtechtips ~]# date 090615002012 Thu Sep  6 15:00:00 SGT 2012 where as: 09 = month (September) 06 = day 15 = hour 00 = min 2012 = year Now it’s set, as simple as that: [root@linuxtechtips ~]# date Thu Sep  6 15:00:01 SGT 2012 Another example, you want it to change to 20th of December, 2012, 10:45pm [root@linuxtechtips ~]# date 122022452012 Thu Dec 20 22:45:00 SGT 2012 Viola!!! [root@linuxtechtips ~]# date Thu Dec 20 22:45:03 SGT 2012 Now if you want to challenge yourself, then you can use this as well: Using our example date above, use the date comman