1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

TUTORIAL Install gMail as SMTP Relay Host for SendMail

Discussion in 'Add-On Install Instructions' started by wardmundy, Mar 16, 2008.

  1. wardmundy

    wardmundy
    Expand Collapse
    Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    12,150
    Likes Received:
    1,703
    True to form, Comcast has recently taken to screwing its customers by shutting down port 25 on your cable modem. Other ISPs will no doubt follow suit. This means you not only can't run your own SMTP server on a box such as PBX in a Flash, but you can't even connect through a mail client to your provider's SMTP server to send mail on the traditional port 25. To find out whether your provider has done it to you, issue the following command. If it times out, you lose. Otherwise, you're still OK. Type quit to exit.
    [SIZE=-1]
    telnet cutedgesystems.com 25[/SIZE]

    What you basically need is an SMTP relay host that supports port 587 and 465 mail traffic. We already have documented how to do this with Comcast, but you also can use gMail. Also take a look at this simple way to enable a relay host directly in SendMail.

    Configuring gMail to handle the change was painful so I thought I'd document the steps for those of you that get screwed next. :mad5: When you complete the following steps, outbound emails (including voicemails that have been configured for delivery by email in FreePBX) will be sent from your PBX in a Flash server through SendMail to gMail's secure server on port 587 or 465 for forwarding. You will need your gMail username and password to complete this install.

    IMPORTANT: First enable sign in from Less Secure Apps for your Gmail account here.

    This tutorial is for PBX in a Flash systems only and assumes you already have performed the email fixup steps outlined in this Nerd Vittles tutorial. If not, do that first. Then log into your server as root and issue the following commands in order:
    Code:
    cd /etc/mail
    hostname -f > genericsdomain
    touch genericstable
    makemap -r hash genericstable.db < genericstable
    mv sendmail.mc sendmail.mc.original
    wget http://nerdvittles.dreamhosters.com/pbxinaflash/source/sendmail/sendmail.mc.gmail
    cp sendmail.mc.gmail sendmail.mc
    mkdir -p auth
    chmod 700 auth
    cd auth
    echo AuthInfo:smtp.gmail.com \"U:smmsp\" \"I:user_id\" \"P:password\" \"M:PLAIN\" > client-info
    echo AuthInfo:smtp.gmail.com:587 \"U:smmsp\" \"I:user_id\" \"P:password\" \"M:PLAIN\" >> client-info
    echo AuthInfo:smtp.gmail.com:465 \"U:smmsp\" \"I:user_id\" \"P:password\" \"M:PLAIN\" >> client-info
    # Stop here and edit client-info (nano -w client-info) in both lines.
    # Replace  user_idwith your gMail account name without @gmail.com
    # Replace password with your real gMail password
    # Be sure to replace the double-quotes shown above if they don't appear in the file!!!
    # Save your changes (Ctrl-X, Y, then Enter)
    chmod 600 client-info
    makemap -r hash client-info.db < client-info
    cd ..
    yum -y install sendmail-cf
    make
    service sendmail restart
    
    NOTE: On Ubuntu, Debian, and Raspberry Pi, you may get errors restarting SendMail. If so, execute the following commands and then press Enter for all of the default settings in the last step.

    IMPORTANT: BEFORE CONTINUING, Your hostname in /etc/hosts and /etc/hostname MUST be a fully-qualified domain for this SendMail implementation, e.g. raspberrypi3.incrediblepbx.com will work even though it is not resolvable.

    Code:
    sed -i 's|sendmail-cf|sendmail\/cf' /etc/mail/sendmail.mc
    sed -i 's|sendmail-cf|sendmail\/cf|' /etc/mail/sendmail.mc
    sed -i 's|sendmail-cf|sendmail\/cf|' /etc/mail/Makefile
    sed -i 's|sendmail-cf|sendmail\/cf|' /etc/mail/sendmail.cf
    sed -i 's|sendmail-cf|sendmail\/cf|' /etc/mail/databases
    sed -i 's|sendmail-cf|sendmail\/cf|' /etc/mail/sendmail.mc.gmail
    sed -i 's|sendmail-cf|sendmail\/cf|' /etc/mail/sendmail.cf.errors
    sendmailconfig
    
    Now you should be back in business. Special thanks to Linux Home Automation and this thread for all the helpful information.

    Test your new mail setup by sending yourself an email using your email address below. Be sure to check your SPAM folder.
    Code:
    apt-get install mailutils -y
    echo "test" | mail -s testmessage yourname@yourdomain.com
    WARNING: This design has not been tested with direct exposure of SendMail to the Internet and should NOT be used without at least the PBX in a Flash firewall in place to block inbound port 25 and 587 and 465 traffic. If you don't heed this advice, you may risk turning your server into an Internet mail relay host in which case you'll probably lose (what's left of) your broadband account for aiding and abetting the proliferation of... :spam:
     
    #1 wardmundy, Mar 16, 2008
    Last edited: Apr 13, 2016
    pethson likes this.
  2. cramerjd

    cramerjd
    Expand Collapse
    New Member

    Joined:
    Oct 22, 2007
    Messages:
    88
    Likes Received:
    0
    I already removed sendmail in lue of postfix. Postfix isn't working anyway. How do remove postfix to readd sendmail to do the above.
     
  3. The Deacon

    The Deacon
    Expand Collapse
    Guru

    Joined:
    Jan 29, 2008
    Messages:
    279
    Likes Received:
    6
    I followed the example line by line. I used to use comcast, but about a week or so ago, it quit working... So I switched to gmail...

    Maybe I'm missing something, but I can't get this to work for the LIFE of me. Here is the maillog entry:


    Apr 2 19:32:09 pbx sendmail[17154]: m332W9pT017154: from=root, size=953, class=0, nrcpts=1, msgid=<200804030232.m332W9pT017154@pbx.highness.com>, relay=root@localhost
    Apr 2 19:32:10 pbx sendmail[17155]: m332W9Zv017155: from=<root@pbx.highness.com>, size=1233, class=0, nrcpts=1, msgid=<200804030232.m332W9pT017154@pbx.highness.com>, proto=ESMTP, daemon=MTA, relay=pbx.highness.com [127.0.0.1]
    Apr 2 19:32:10 pbx sendmail[17154]: m332W9pT017154: to=sales@highness.com, ctladdr=root (0/0), delay=00:00:01, xdelay=00:00:01, mailer=relay, pri=30953, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (m332W9Zv017155 Message accepted for delivery)
    Apr 2 19:32:10 pbx sendmail[17157]: STARTTLS=client, relay=smtp.gmail.com, version=TLSv1/SSLv3, verify=FAIL, cipher=DES-CBC3-SHA, bits=168/168
    Apr 2 19:32:10 pbx sendmail[17157]: AUTH=client, relay=smtp.gmail.com [209.85.147.109], authinfo failed
    Apr 2 19:32:10 pbx sendmail[17157]: m332W9Zv017155: to=<sales@highness.com>, delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=121233, relay=smtp.gmail.com [209.85.147.109], dsn=5.0.0, stat=Service unavailable
    Apr 2 19:32:10 pbx sendmail[17157]: m332W9Zv017155: m332WAZv017157: DSN: Service unavailable
    Apr 2 19:32:10 pbx sendmail[17157]: m332WAZv017157: to=<root@pbx.highness.com>, delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=32454, relay=smtp.gmail.com, dsn=5.0.0, stat=Service unavailable
    Apr 2 19:32:10 pbx sendmail[17157]: m332WAZv017157: m332WAZw017157: return to sender: Service unavailable
    Apr 2 19:32:10 pbx sendmail[17157]: m332WAZw017157: to=root, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=33478, dsn=2.0.0, stat=Sent


    The highlighted lines are the ones that I'm the most concerned about. The /etc/mail/auth/client-info file exists and I can use the login/password to log into my gmail.com account...

    I'm obviously missing something, but what it is?

    Thanks!

    -Rick

     
  4. cramerjd

    cramerjd
    Expand Collapse
    New Member

    Joined:
    Oct 22, 2007
    Messages:
    88
    Likes Received:
    0
    I already removed sendmail in lue of postfix. Postfix isn't working anyway. How do remove postfix to readd sendmail to do the above.
     
  5. cramerjd

    cramerjd
    Expand Collapse
    New Member

    Joined:
    Oct 22, 2007
    Messages:
    88
    Likes Received:
    0
    I FINALLY GOT THIS WORKING, THANKS WARD.

    BTW i was having a hard time because everyone recommended going postfix and i couldn't figure out how to go back to sendmail from postfix.

    Here is how i did it for those that made the same mistake.

    # rpm -e --nodeps postfix
    # yum -y install sendmail
     
  6. birkey

    birkey
    Expand Collapse
    New Member

    Joined:
    Dec 4, 2007
    Messages:
    3
    Likes Received:
    0
    TheDeacon, Did you get your problem solved? I have the same issue
     
  7. cramerjd

    cramerjd
    Expand Collapse
    New Member

    Joined:
    Oct 22, 2007
    Messages:
    88
    Likes Received:
    0
    #7 cramerjd, Apr 17, 2008
    Last edited by a moderator: Apr 6, 2016
  8. birkey

    birkey
    Expand Collapse
    New Member

    Joined:
    Dec 4, 2007
    Messages:
    3
    Likes Received:
    0
    I have followed the instructions to the "T" x 10


    I have a DNS name for my Astrisk system voice.[mydnsname].com

    when I try to send a email from the command line I see the following in my maillog

    Apr 17 14:15:19 voice sendmail[8005]: m3HJFJ45008005: from=root, size=393, class=0, nrcpts=1, msgid=<200804171915.m3HJFJ45008005@voice.[mydnsname].com>, relay=root@localhost
    Apr 17 14:15:19 voice sendmail[8006]: m3HJFJuJ008006: from=<root@voice.[mydnsname].com>, size=688, class=0, nrcpts=1, msgid=<200804171915.m3HJFJ45008005@voice.[mydnsname].com>, proto=ESMTP, daemon=MTA, relay=voice.[mydnsname].com [127.0.0.1]
    Apr 17 14:15:19 voice sendmail[8005]: m3HJFJ45008005: to=touser@somedomain.com, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30393, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (m3HJFJuJ008006 Message accepted for delivery)
    Apr 17 14:15:19 voice sendmail[8008]: STARTTLS=client, relay=smtp.gmail.com, version=TLSv1/SSLv3, verify=FAIL, cipher=DES-CBC3-SHA, bits=168/168
    Apr 17 14:15:19 voice sendmail[8008]: AUTH=client, relay=smtp.gmail.com [64.233.167.109], authinfo failed
    Apr 17 14:15:19 voice sendmail[8008]: m3HJFJuJ008006: to=<touser@somedomain.com>, ctladdr=<root@voice.[mydnsname].com> (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=120688, relay=smtp.gmail.com [64.233.167.109], dsn=5.0.0, stat=Service unavailable
    Apr 17 14:15:19 voice sendmail[8008]: m3HJFJuJ008006: m3HJFJuJ008008: DSN: Service unavailable
    Apr 17 14:15:19 voice sendmail[8008]: m3HJFJuJ008008: to=<root@voice.[mydnsmane].com>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31939, dsn=2.0.0, stat=Sent

    notice the authinfo failed and verify=FAIL
     
  9. The Deacon

    The Deacon
    Expand Collapse
    Guru

    Joined:
    Jan 29, 2008
    Messages:
    279
    Likes Received:
    6
    I too struggled with that SAME issue. Couldn't figure it out for the life of me. Kept filling up the root mailbox with "message undeliverable" messages...

    Ended up spending $15/year to dyndns.org to let me use their mail gateway.

    Best $15 I ever spent...
     
  10. ysedeyn

    ysedeyn
    Expand Collapse
    New Member

    Joined:
    Dec 7, 2007
    Messages:
    10
    Likes Received:
    0
    sendmail (neither postfix) was not working for me until I edited the /etc/hosts file to add my dyndns.org name to the following line:

    127.0.0.1 <name>.dyndns.org asterisk1.local pbx.local pbx localhost.localdomain localhost

    Yves.
     
  11. wardmundy

    wardmundy
    Expand Collapse
    Nerd Uno

    Joined:
    Oct 12, 2007
    Messages:
    12,150
    Likes Received:
    1,703
  12. cramerjd

    cramerjd
    Expand Collapse
    New Member

    Joined:
    Oct 22, 2007
    Messages:
    88
    Likes Received:
    0
    I have a feeling your getting stuck in the same place I was with gmail. I got the same message you got.

    Log into your gmail account and go to settings. Make sure to enable IMAP (don't know why it seems unrelated) instead of POP. I did this just to test when i was having issues and it worked perfectly ever since.

    Also make sure the DNS name your using for your server is actually valid (you can go to your friends house and access your PIAF with the DNS name you supplied).
     
  13. jebradley

    jebradley
    Expand Collapse
    Member

    Joined:
    Oct 30, 2007
    Messages:
    36
    Likes Received:
    0
    Has anybody looked at sSMTP?

    I just came across this article
    http://www.linux.com/feature/132006
    that describes a simplified SMTP agent, designed to use a remote SMTP server (your ISP's).

    It sounds like it might be just what is needed.

    I'm not about to try it, as I currently have a working sendmail configuration relayed through my ISP. The sending email address isn't correct, among other things, but it works, so I'm not about to try anything different at the present time. It was a long, convoluted path to get it working at all, back and forth and back again, etc., from sendmail to postfix and back with numerous changes.
     
  14. undrhil

    undrhil
    Expand Collapse
    Member

    Joined:
    Feb 7, 2008
    Messages:
    81
    Likes Received:
    0
    I believe the main problem with these instructions is the use of the echo command. The echo command stips double-quotes from whatever is echo'd so that client-info file doesn't contain the double-quotes. To fix this problem, when you edit client-info to change user-id and password, reinsert the double-quotes. This fixed it for me.

    Undrhil
     
  15. ednunnemaker

    ednunnemaker
    Expand Collapse
    New Member

    Joined:
    Oct 31, 2007
    Messages:
    118
    Likes Received:
    0
    how

    how do i undo the changes made with this write up? its not working and i think its due to the exchange server at the customers site, i can send email to myself al day long but a soon as i try to send it to them it never reaches the destination, i think they are blocking it somehow, they claim they don't even see the message attempt to be delivered, thought maybe i'll go back to square one and try the normal route. thank you,
     
  16. dad311

    dad311
    Expand Collapse
    Guru

    Joined:
    Jan 13, 2008
    Messages:
    601
    Likes Received:
    1
    Nice write-up. Just thought I would note that I needed to remove/delete my sendmail.cf file before doing the make command. The make command would run, but not update the sendmail.cf file.
     
  17. cjkeeme

    cjkeeme
    Expand Collapse
    Guru

    Joined:
    Jun 18, 2008
    Messages:
    203
    Likes Received:
    0
    I am interested in using this with my Google Apps email. This way the received email is from my domain instead of @gmail.

    Google Apps uses the same smtp.gmail.com on port 587. My guess is it won't be difficult to accomplish, but I don't know where to begin.

    Any help figuring this out is greatly appreciated.
     
  18. discodave1977

    discodave1977
    Expand Collapse
    New Member

    Joined:
    Jul 6, 2008
    Messages:
    61
    Likes Received:
    0
    I use Bell Sympatico at home and this fix works like a charm for me. ty ty ty!
     
  19. badwolf

    badwolf
    Expand Collapse
    Member

    Joined:
    Feb 17, 2008
    Messages:
    30
    Likes Received:
    0
    what should i set for

    127.0.0.1 pbx.dyndns.org pbx.local pbx localhost.localdomain localhost

    And then make line 6 of /etc/asterisk/vm_general.inc look like the following:

    serveremail=voicemail@pbx.dyndns.org

    Now issue the following two commands to make the changes take effect:

    service network restart
    amportal restart
    The command “setup-mail” can be used from the Linux prompt to set the fully-qualified domain name (FQDN)



    also i tried the instructions but nothing happens for make.
    thanks
     
  20. wnpaul

    wnpaul
    Expand Collapse
    New Member

    Joined:
    Feb 5, 2008
    Messages:
    17
    Likes Received:
    1
    just add your domain name to the username

    Where Ward's instructions say "your gmail username without @gmail.com" you need to put your complete Google Apps email address (in other words with @yourdomain). That is the only difference in the SMTP instructions provided by Google for Gmail and GApps accounts, respectively.
     

Share This Page