Sunday, March 3, 2013

Postfix with Gmail

PostFix with Gmail on CentOS


Here's how I setup a postfix relay using Gmail on CentOS 6.3 Minimal

Started off by following the directions here:
http://charlesauer.net/tutorials/centos/postfix-as-gmail-relay-centos.php

Initially, it did not work.  I saw these errors in /var/log/maillog

warning: SASL authentication failure: No worthy mechs found

03DD726033A: SASL authentication failed; cannot authenticate to server smtp.gmail.com[74.125.25.109]: no mechanism available

warning: SASL authentication failure: No worthy mechs found

to=<xxxxxx@yahoo.com>, relay=smtp.gmail.com[74.125.25.108]:587, delay=145, delays=144/0.14/0.73/0, dsn=4.7.0, status=deferred (SASL authentication failed; cannot authenticate to server smtp.gmail.com[74.125.25.108]: no mechanism available)

Typically, these errors arise when the remote server only offers plaintext authentication mechanisms.  To check this I turned on postfix debugging by adding the following lines to main.cf.  Don't forget to restart Postfix after these changes.

debug_peer_list=smtp.gmail.com
debug_peer_level=3

With the debugging now turned on, I attempted another email and I saw this:

smtp_sasl_authenticate: smtp.gmail.com[74.125.25.108]:587: SASL mechanisms LOGIN PLAIN XOAUTH XOAUTH2

That told me that Gmail was in fact accepting encrypted authentication mechanisms.  Word to the wise, unless you are developing code, you probably don't need to turn the debug level up higher than three on postfix.

The solution to my problem was at http://www.postfix.org/SASL_README.html all along.

Postfix logs the following message:

SASL authentication failure: No worthy mechs found

When the libplain.so or liblogin.so modules are not installed in the /usr/lib/sasl2 directory.

The fix was easy, install the additional sasl modules using this:

yum install cyrus-sasl-plain

Conclusion
Simply installing postfix is not enough when you want to use SASL to relay mail through another server.  You must also be sure to install the additional SASL modules.

5 comments:

  1. This helped me to get relaying working! Thank you! I installed CentOS from the minimal ISO, so I didn't have cyrus-sasl-plain installed, either.

    ReplyDelete
  2. I installed from the minimal ISO as well and had this issue. Thanks!

    ReplyDelete
  3. Awesome -- that did the trick after following this guide: http://freelinuxtutorials.com/quick-tips-and-tricks/configure-postfix-to-use-gmail-in-rhelcentos/

    ReplyDelete
  4. Worked also on debian! :)
    Install: "sasl2-bin libsasl2-modules"

    ReplyDelete
  5. USA Gmail Help Numbers so that Citizens of United States of America, can call from any geo areas over the US. Likewise they additionally have toll free Gmail Help Number for toll free calling from any geographic area over the Canada. http://robetbuckner.webnode.com/how-to-contact-gmail-support-by-phone-directly-i-dial-1-866-688-6581/

    ReplyDelete