TUTORIAL Install gMail as SMTP SmartHost for SendMail

wardmundy

Nerd Uno
Joined
Oct 12, 2007
Messages
19,168
Reaction score
5,199
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://incrediblepbx.com/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 [email protected]

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:
 
Last edited:

cramerjd

New Member
Joined
Oct 22, 2007
Messages
88
Reaction score
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.
 

The Deacon

Guru
Joined
Jan 29, 2008
Messages
296
Reaction score
14
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=<[email protected]>, relay=root@localhost
Apr 2 19:32:10 pbx sendmail[17155]: m332W9Zv017155: from=<[email protected]>, size=1233, class=0, nrcpts=1, msgid=<[email protected]>, proto=ESMTP, daemon=MTA, relay=pbx.highness.com [127.0.0.1]
Apr 2 19:32:10 pbx sendmail[17154]: m332W9pT017154: [email protected], 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=<[email protected]>, 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=<[email protected]>, 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

 

cramerjd

New Member
Joined
Oct 22, 2007
Messages
88
Reaction score
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.
 

cramerjd

New Member
Joined
Oct 22, 2007
Messages
88
Reaction score
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
 

birkey

New Member
Joined
Dec 4, 2007
Messages
3
Reaction score
0
TheDeacon, Did you get your problem solved? I have the same issue
 

birkey

New Member
Joined
Dec 4, 2007
Messages
3
Reaction score
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: [email protected], 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=<[email protected]>, 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
 

The Deacon

Guru
Joined
Jan 29, 2008
Messages
296
Reaction score
14
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...
 

ysedeyn

New Member
Joined
Dec 7, 2007
Messages
10
Reaction score
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.
 

cramerjd

New Member
Joined
Oct 22, 2007
Messages
88
Reaction score
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).
 

jebradley

Member
Joined
Oct 30, 2007
Messages
36
Reaction score
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.
 

undrhil

Member
Joined
Feb 7, 2008
Messages
158
Reaction score
12
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
 

ednunnemaker

New Member
Joined
Oct 31, 2007
Messages
118
Reaction score
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,
 

dad311

Guru
Joined
Jan 13, 2008
Messages
604
Reaction score
2
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.
 

cjkeeme

Guru
Joined
Jun 18, 2008
Messages
203
Reaction score
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.
 

discodave1977

New Member
Joined
Jul 6, 2008
Messages
61
Reaction score
0
I use Bell Sympatico at home and this fix works like a charm for me. ty ty ty!
 

badwolf

Member
Joined
Feb 17, 2008
Messages
44
Reaction score
2
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:

[email protected]

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
 

wnpaul

New Member
Joined
Feb 5, 2008
Messages
17
Reaction score
1
just add your domain name to the username

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.

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.
 

Members online

No members online now.

Forum statistics

Threads
25,778
Messages
167,504
Members
19,199
Latest member
leocipriano
Get 3CX - Absolutely Free!

Link up your team and customers Phone System Live Chat Video Conferencing

Hosted or Self-managed. Up to 10 users free forever. No credit card. Try risk free.

3CX
A 3CX Account with that email already exists. You will be redirected to the Customer Portal to sign in or reset your password if you've forgotten it.
Top