Need help setting up a gmail relay in postfix on Fedora 19

Discussion in 'Server Operation' started by PatrickDickey, Nov 19, 2013.

  1. PatrickDickey

    PatrickDickey New Member

    Hi everyone,

    I'm trying to set up an Amahi Home Server using Fedora 19 (the latest version of Amahi available), and want to set up Postfix to relay messages for the root email, via my gmail account. I have this set up on another server already, but for some reason the steps don't work on the new server (it works perfect on the old server).

    Here is the relevant portion of main.cf from the "OLD" server:
    Code:
    # sets gmail as a relay
    relayhost=[smtp.gmail.com]:587
    
    # uses tls and starts it
    smtp_use_tls=yes
    
    # use sasl when authenticating to foreign SMTP servers
    smtp_sasl_auth_enable=yes
    
    # path to password map file
    smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd
    
    # list of CA's to trust when verifying server certificate
    smtp_tls_CAfile=/etc/ssl/certs/ca-bundle.crt
    
    # elminiates default security options which are incompatible with gmail
    smtp_sasl_security_options=
    
    # adding some policy information to try and fix need starttls error
    
    smtp_tls_policy_maps = hash:/etc/postfix/tls_policy
    
    
    And the sasl_passwd (with actual email and password removed)
    Code:
    [smtp.gmail.com]:587 [email protected]:
    
    And the tls_policy file:

    Code:
    [smtp.gmail.com]:587 encrypt
    
    Originally I tried copying all of the files from the old computer directly to the new one. That didn't work. So I redid everything, and have tried various methods to get the relay working.

    I guess my questions are 1: What am I missing here? and 2: Why did it work on one computer, but not the other (the only real difference being the old server is a 32-bit and the new one is 64-bit)?

    I just tried clearing out all of my relay settings on the new server, and pasting in the same settings from the old server (in main.cf). When I restarted postfix, and sent my test mail, I get this:

    Code:
    Nov 19 07:19:58 localhost postfix/master[14088]: daemon started -- version 2.10.2, configuration /etc/postfix
    Nov 19 07:20:05 localhost postfix/pickup[14089]: 323681801AD: uid=0 from=<root>
    Nov 19 07:20:05 localhost postfix/cleanup[14099]: 323681801AD: message-id=<[email protected]>
    Nov 19 07:20:05 localhost postfix/qmgr[14090]: 323681801AD: from=<[email protected]>, size=507, nrcpt=1 (queue active)
    Nov 19 07:20:05 localhost postfix/smtp[14101]: warning: SASL authentication failure: No worthy mechs found
    Nov 19 07:20:05 localhost postfix/smtp[14101]: 323681801AD: SASL authentication failed; cannot authenticate to server smtp.gmail.com[74.125.142.109]: no mechanism available
    Nov 19 07:20:06 localhost postfix/smtp[14101]: warning: SASL authentication failure: No worthy mechs found
    Nov 19 07:20:06 localhost postfix/smtp[14101]: 323681801AD: SASL authentication failed; cannot authenticate to server smtp.gmail.com[2607:f8b0:4002:c01::6c]: no mechanism available
    Nov 19 07:20:07 localhost postfix/smtp[14101]: warning: SASL authentication failure: No worthy mechs found
    Nov 19 07:20:07 localhost postfix/smtp[14101]: 323681801AD: to=<[email protected]>, relay=smtp.gmail.com[74.125.142.108]:587, delay=2.2, delays=0.11/0.05/2/0, dsn=4.7.0, status=deferred (SASL authentication failed; cannot authenticate to server smtp.gmail.com[74.125.142.108]: no mechanism available)
    
    Any help is greatly appreciated. Have a great day.:)
    Patrick.
     
  2. Quaxth

    Quaxth Member

    Are both servers on the same LAN? If so, there's maybe a Port forwarding conflict!
     
  3. PatrickDickey

    PatrickDickey New Member

    Hi there,

    Yes they're both on the same LAN. However nothing else uses them to send mail out. They're set up strictly so that email messages sent via the operating system or applications to the root account will be forwarded to my gmail account.

    Originally (and just about an hour ago), I followed the steps on https://calomel.org/postfix.html for setting up the relay. As I said, it worked on my other computer, but not on this one. The main difference is the old computer is 32-bit and this one is 64-bit.

    Here is the code that I have in my new server (and I have all applicable cert files in place)

    Code:
    # Setting up gmail relay for root email address
    
    ### GMAIL Relay Host and Smtp-Auth options
    relayhost = [smtp.gmail.com]:587
    smtp_tls_CAfile = /etc/postfix/cacert.pem
    smtp_tls_cert_file = /etc/postfix/example_gmail-cert.pem
    smtp_tls_key_file = /etc/postfix/example_gmail-key.pem
    smtp_tls_session_cache_database = btree:/var/run/smtp_tls_session_cache
    smtp_use_tls = yes
    smtpd_tls_CAfile = /etc/postfix/cacert.pem
    smtpd_tls_cert_file = /etc/postfix/example_gmail-cert.pem
    smtpd_tls_key_file = /etc/postfix/example_gmail-key.pem
    smtpd_tls_received_header = yes
    smtpd_tls_session_cache_database = btree:/var/run/smtpd_tls_session_cache
    smtpd_use_tls = yes
    tls_random_source = dev:/dev/urandom
    smtpd_sasl_auth_enable = no
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtpd_sasl_local_domain = $myhostname
    smtp_sasl_security_options = noanonymous
    #smtp_sasl_security_options =
    smtp_sasl_tls_security_options = noanonymous
    smtpd_sasl_application_name = smtpd
    
    Also, when I start the postfix server, I get the following warnings (only on the "new" server)

    Code:
    [root@localhost postfix]# postfix start
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    /usr/sbin/postconf: warning: /etc/postfix/main.cf: unused parameter: smtpd_sasl_application_name=smtpd
    postfix/postfix-script: starting the Postfix mail system
    
    I know this setup worked in an older version of Fedora/Amahi. I guess what I'm looking for is an updated (to Fedora 19) tutorial on how to set up the gmail relay with postfix. Because this one isn't working, and neither is the version that I used to set up my other server.

    That other version can be found at http://mhawthorne.net/posts/postfix-configuring-gmail-as-relay.html and my personal implementation of it is at my site http://patscomputerservices.com/setting-up-a-google-relay-host-using-postfix-on-fedora-19/

    I should note that at the end of the day, I'm going to pull the old server offline and only use the new one. But until all of the files on the old one are taken care of, I have to run both at once.

    Thanks for your help. Have a great day.:)
    Patrick.
     
  4. PatrickDickey

    PatrickDickey New Member

    ARRRRRRRRRRGGGGGGGGGGGGGHHHHHHHHHHHHHHHHHH!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    OK, I've figured out the problem and potentially solved it...

    After a lot of googling, and trying different things, I came across this:

    http://serverfault.com/questions/32...-trying-to-relay-email-to-gmail-using-postfix

    And when I followed the answer (#2) yum install cyrus-sasl cyrus-sasl-lib cyrus-sasl-plain the test email (along with all of the "Deferred" ones) successfully sent.

    Here's the relevant portion of my main.cf file.

    Code:
    # Setting up gmail relay for root email address
    
    ### GMAIL Relay Host and Smtp-Auth options
    relayhost = [smtp.gmail.com]:587
    smtp_tls_CAfile = /etc/postfix/cacert.pem
    smtp_tls_cert_file = /etc/postfix/example_gmail-cert.pem
    smtp_tls_key_file = /etc/postfix/example_gmail-key.pem
    smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_tls_session_cache
    smtp_use_tls = yes
    smtpd_tls_CAfile = /etc/postfix/cacert.pem
    smtpd_tls_cert_file = /etc/postfix/example_gmail-cert.pem
    smtpd_tls_key_file = /etc/postfix/example_gmail-key.pem
    smtpd_tls_received_header = yes
    smtpd_tls_session_cache_database = btree:/var/lib/postfix/smtpd_tls_session_cache
    smtpd_use_tls = yes
    tls_random_source = dev:/dev/urandom
    smtpd_sasl_auth_enable = no
    smtp_sasl_auth_enable = yes
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtpd_sasl_local_domain = $myhostname
    smtp_sasl_security_options = noanonymous, noplaintext
    #smtp_sasl_security_options =
    smtp_sasl_tls_security_options = noanonymous
    smtpd_sasl_path = smtpd
    smtpd_tls_loglevel = 3
    
    I'll remove the smtpd_tls_loglevel = 3 line when I know it's working for sure.

    So, for anyone trying to do this, you can probably remove the "noplaintext" portion from my main.cf file, and install the modules (in my case, it was the cyrus-sasl-plain module).

    Thanks for the help that people gave, and sorry that I'm answering my own question.

    Have a great day.:)
    Patrick.
     
  5. Quaxth

    Quaxth Member

    It's good to see that you got things working. Don't ever need to be sorry for such!

    One thing you may should keep in mind: Google allows a max of 500 messages per day using their SMTP Servers. Also sometimes they limit the connection to 1 at the same time. If you use the same SMTP on 2 different machines, you may could face problems.

    There's an alternative, use an Open Relay! You could use the the following link: http://www.mydnstools.info/smtprelay for to check and SMTP Server is running as Open Relay or is need Authentication or is a Closed Relay. If you want to check, start with the SMTP Server of your ISP!
     

Share This Page