LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   How to configure sendmail to use Gmail as SMTP server? (https://www.linuxquestions.org/questions/slackware-14/how-to-configure-sendmail-to-use-gmail-as-smtp-server-802815/)

narke 04-19-2010 05:03 AM

How to configure sendmail to use Gmail as SMTP server?
 
Hi,

It seems my sendmail (running in slackware 13.0) cannot send out emails correctly. I guess I need to tell it what is the smtp server to use. And, I heard, gmail's smtp server is available to use for this purpose. Can anyone please help me to configure my sendmail this way?

Thanks in advance.

-
narke

ripp3r 04-19-2010 05:10 AM

Quote:

Originally Posted by narke (Post 3940100)
Hi,

It seems my sendmail (running in slackware 13.0) cannot send out emails correctly. I guess I need to tell it what is the smtp server to use. And, I heard, gmail's smtp server is available to use for this purpose. Can anyone please help me to configure my sendmail this way?

Thanks in advance.

-
narke

well the server address is smtp.gmail.com
And if you use the SSL the port will be 465

hope this help

narke 04-19-2010 09:29 AM

Quote:

Originally Posted by ripp3r (Post 3940108)
well the server address is smtp.gmail.com
And if you use the SSL the port will be 465

but ... how to set it with sendmail? and, how do i decide if i will use SSL or not?

thanks.


-
narke

Richard Cranium 04-19-2010 12:43 PM

You should read the files
Code:

/usr/share/sendmail/cf/cf/sendmail-slackware.mc
and
Code:

/usr/share/sendmail/cf/README
You would uncomment the
Code:

dnl define(`SMART_HOST',`mailserver.example.com')
line as well as setting the DAEMON_OPTIONS for the outbound portion.

ripp3r 04-20-2010 09:02 AM

And maybe this can help you a bit:

http://www.linuxhomenetworking.com/w...x_Mail_Servers

narke 04-20-2010 09:29 AM

hey! thank you for all your replies. i will dive to study to see if i can work it out. Thanks again!

narke 04-21-2010 07:46 PM

Quote:

Originally Posted by narke (Post 3941452)
hey! thank you for all your replies. i will dive to study to see if i can work it out. Thanks again!

hi, experts

after read some documents i now come back with a feeling that it is really not an easy thing to learn. on the other hand, my purpose is only to let my sendmail use gmail's smtp relay service, so i think i need a minimum example that show the points. learning from an example is easier than go through the very long sendmail manuals.

it will be highly appreciated if you can help.


P.S. my smtp host does not has a DNS MX record and gets a private IP address, it is behind a firewall, but i can access internet.


-
narke

T3slider 04-21-2010 08:00 PM

If you want the easy way out, get msmtp. It is an smtp *client* and does what you want without fuss. sendmail is by default an smtp *server*, but can be strong-armed into acting as an smtp client -- but as you have seen it is not simple.

dive 04-21-2010 09:16 PM

I did write a howto on using sendmail relay to the virginmedia server (link in sig). The vm server uses gmail so should be almost the same. The problem I found is that I had to use stunnel to create an ssl tunnel for sendmail to relay through.

So yes, msmtp is a much easier solution to it, and it's on slackbuilds.org.

dugan 04-21-2010 11:26 PM

Quote:

Originally Posted by T3slider (Post 3943377)
sendmail is by default an smtp *server*

My thoughts exactly.

Why would you use sendmail to send email to another smtp server? I don't know what setup you have, but it sounds as if anything would be simpler.

If you're simply trying to send emails with Mutt, then I third the suggestion for msmtp.

narke 04-22-2010 01:21 AM

Quote:

Originally Posted by dugan (Post 3943524)
My thoughts exactly.

Why would you use sendmail to send email to another smtp server? I don't know what setup you have, but it sounds as if anything would be simpler.

If you're simply trying to send emails with Mutt, then I third the suggestion for msmtp.

It's because my host is running some web services such wiki and a forum, their abilities of sending out email to users is based on the fact that the host gets smtp.

fancylad 04-22-2010 05:50 PM

i don't think that gmail wants smtp servers to be using them as a mail relay. google's smtp server is intended for emails destined for their users (ie users with a @gmail.com account). i doubt they would allow you to relay email through them. even if they did you would have to authenticate to their smtp server first and this is something that smtp servers normally do not do. usually if you want an smtp server to be able to relay email through another smtp server they would have to permit their ip in order to do this. i am not saying that what you want to do is impossible; however it is something that smtp servers generally do not do nor need to do. if you need to relay email through an smtp server you should probably be using your ISP's smtp server.

granth 04-22-2010 06:11 PM

Simple...


1. Obvious
Code:

su - root
2. Create your SSL certs
Code:

mkdir /etc/mail/certs
chmod 700 /etc/mail/certs
cd /etc/mail/certs
openssl req -new -x509 -keyout mykey.pem -out mycert.pem -days 3650

3. Create your auth credentials
Code:

mkdir /etc/mail/auth
chmod 700 /etc/mail/auth
cd /etc/mail/auth
echo 'AuthInfo:smtp.gmail.com "U:root" "I:youraddress@gmail.com" "P:yourpassword' > client-info
makemap -r hash client-info.db < client-info
chmod 600 client-info*

4. Modify the default sendmail configuration
Code:

cd /etc/mail
mv sendmail.cf sendmail.cf.orig
cp /usr/share/sendmail/cf/cf/sendmail-slackware.mc ./sendmail-gmail.mc

Edit /etc/mail/sendmail-gmail.mc so the following lines are after "OSTYPE(`linux')dnl":

Code:

define(`SMART_HOST',`smtp.gmail.com')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash /etc/mail/auth/client-info')dnl
define(`CERT_DIR', `MAIL_SETTINGS_DIR`'certs')
define(`confCACERT_PATH', `CERT_DIR')
define(`confCACERT', `CERT_DIR/mycert.pem')
define(`confSERVER_CERT', `CERT_DIR/mycert.pem')
define(`confSERVER_KEY', `CERT_DIR/mykey.pem')
define(`confCLIENT_CERT', `CERT_DIR/mycert.pem')
define(`confCLIENT_KEY', `CERT_DIR/mykey.pem')

5. Compile your cf
Code:

m4 sendmail-gmail.mc > sendmail.cf
6. Restart sendmail
Code:

/etc/rc.d/rc.sendmail restart
7. Test it
Code:

echo "tester" | mailx -s "test email" sample@isp.com
8. Have a beer

EXTRA:
I believe gmail rewrites relayed message headers. However, some ISP-provided SMTP relays do not do this. Therefore, if your sendmail server does not have a FQDN, some spam filters will block your message.
This problem can be avoided by spoofing your headers. Using mutt, just add this line to your .muttrc :
Quote:

set envelope_from=yes
set from="My Name <my.address@isp.net>"
Let me know if you need any more help. Sendmail is an MTA. Most people don't understand this concept...
You are now on the road to enlightenment.


EDIT: If your ISP is blocking port 25, add this following line to your sendmail.mc to change the port to 587:
Code:

define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl

thatquietboy 04-22-2010 07:37 PM

mailertable
 
too much work, i use mailertable. just remember to
Code:

makemap hash /etc/mail/mailertable.db < /etc/mail/mailertable
after you edit it.

narke 04-22-2010 10:11 PM

It's very strange! Before I post the first message in the thread, I thought that my host should not have ability to send out email without really a try, because the host only have a private IP addres (10.x.x.x) and sit behind a firewall.

But, today after I really tried it, I found the story is actually a little different. It can send out message (via mutt) to my company email address, but it just can not send out message to external email adress (such as my gmail account). And, I have totally no idea how this can happen!

Here are mail log when I sent email to my company email adress:

---------------
Apr 23 10:27:10 svr21 sendmail[14162]: o3N2RAUo014162: from=woody, size=307, cla
ss=0, nrcpts=1, msgid=<20100423022710.GA14159@svr21.ap.foo.net>, relay=woody@localhost

Apr 23 10:27:10 svr21 sm-mta[14163]: o3N2RAvk014163: from=<woody@svr21.foocompany.com>, size=466, class=0, nrcpts=1, msgid=<20100423022710.GA14159@svr21.ap.foo.net>, proto=ESMTP, daemon=MTA, relay=cnzuhsv23.foocompany.com [127.0.0.1]

Apr 23 10:27:10 svr21 sendmail[14162]: o3N2RAUo014162: to=woody.wu@foocompany.com, ctladdr=woody (1000/100), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=3
0307, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (o3N2RAvk014163 Message accepted for delivery)

Apr 23 10:27:12 svr21 sm-mta[14165]: STARTTLS=client, relay=mail.global.frontbridge.com., version=TLSv1/SSLv3, verify=FAIL, cipher=AES128-SHA, bits=128/128

Apr 23 10:27:15 svr21 sm-mta[14165]: o3N2RAvk014163: to=<woody.wu@foocompany.com>, ctladdr=<woody@svr21.foocompany.com> (1000/100), delay=00:00:05, xdelay=00:00:05, mailer=esmtp, pri=120466, relay=mail.global.frontbridge.com. [65.55.88.22], dsn=2.0.0, stat=Sent (<20100423022710.GA14159@svr21.ap.foo.net> Queued mail for delivery)
--------------------

And, here are mail log when I sent email to outside email address:

-------------------
Apr 23 10:52:07 svr21 sendmail[15765]: o3N2q716015765: from=woody, size=301, class=0, nrcpts=1, msgid=<20100423025207.GA15762@svr21.ap.foo.net>, relay=woody@localhost

Apr 23 10:52:12 svr21 sm-mta[15766]: o3N2q7Lv015766: from=<woody@svr21.foocompany.com>, size=458, class=0, nrcpts=1, msgid=<20100423025207.GA15762@svr21.ap.foo.net>, proto=ESMTP, daemon=MTA, relay=cnzuhsv23.foocompany.com [127.0.0.1]

Apr 23 10:52:12 svr21 sendmail[15765]: o3N2q716015765: to=narkewoody@gmail.com,ctladdr=woody (1000/100), delay=00:00:05, xdelay=00:00:05, mailer=relay, pri=30301, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (o3N2q7Lv015766 Messageaccepted for delivery)

Apr 23 10:52:15 svr21 sm-mta[15768]: o3N2q7Lv015766: to=<narkewoody@gmail.com>,ctladdr=<woody@svr21.foocompany.com> (1000/100), delay=00:00:03, xdelay=00:00:03, mailer=esmtp, pri=120458, relay=gmail-smtp-in.l.google.com. [72.14.213.27], dsn=2.0.0, stat=Sent (OK 1271991225 c19si1082758wam.6)
----------------------------

And, here is my /etc/resolve.conf
---------------------------
search ap.foo.net
nameserver 10.86.10.27
nameserver 10.86.10.21
----------------------------

Here is my /etc/hosts
-----------------------
127.0.0.1 cnzuhsv23.foocompany.com localhost
255.255.255.255 all-ones
10.86.12.26 svr21.foocompany.com svr21 es2.0 office
10.86.12.26 cnzuhsv23.foocompany.com
10.86.12.1 gateway
10.86.12.21 svr40
10.86.12.33 es2.1
10.86.12.64 lmt
218.104.197.115 ext-me
10.41.1.60 chzugsv1004
10.41.4.5 cnzuhnb639.ap.foo.net
----------------------


Could anyone please help me to do an analysis? Thanks a lot!

-
narke

bakdong 04-22-2010 10:46 PM

Quote:

Originally Posted by granth (Post 3944539)
Sendmail is an MTA. Most people don't understand this concept...

Here here!

Very useful post. I'm archiving it for future reference. Thanks.

bakdong 04-22-2010 10:52 PM

Quote:

Originally Posted by narke (Post 3944744)
It's very strange! Before I post the first message in the thread, I thought that my host should not have ability to send out email without really a try, because the host only have a private IP addres (10.x.x.x) and sit behind a firewall.

But, today after I really tried it, I found the story is actually a little different. It can send out message (via mutt) to my company email address, but it just can not send out message to external email adress (such as my gmail account). And, I have totally no idea how this can happen!

It's not that you're not sending, it's what the receiver is prepared to do with your message. There's a difference between relaying and receiving for a local domain. Relaying in an uncontrolled way opens the door to spammers so it is discouraged.

ode 04-27-2010 11:19 AM

here's what I do for sending mails from the command line:
in ~/.mailrc add accounts like this:
You can add as many as you like.
Code:

account myaccount {
 set from=myname@mydomain.com
 set smtp=smtpserver.mydomain.com
 set smtp-auth-user=myname@mydomain.com
 set smtp-auth-password=mypassword
 set smtp-auth=login
}

then I send quick mails like this:
Code:

mail -A myaccount -s subject somename@someserver.any
Hope this helps.

dugan 03-09-2014 04:05 PM

I think it's worth bumping this thread for a howto on how to do it with Postfix.

Quote:

Originally Posted by narke (Post 3943628)
It's because my host is running some web services such wiki and a forum, their abilities of sending out email to users is based on the fact that the host gets smtp.

This is fairly common for PHP apps, and there's a technical reason. It's because the Linux implementation of PHP's standard library sends mail through an MTA. See: php.net/mail

Quote:

Originally Posted by granth (Post 3944539)
Simple...

I looked at that, went very pale, and thought, f___ that I'm using Postfix.

Alan Hicks wrote the Postfix SlackBuild (on SBo) to use Dovecot SASL by default. Dovecot SASL isn't available when Postfix connects as a client, so you need to build Postfix to use Cyrus SASL instead. Fortunately, he made that easy:

Code:

SASL=cyrus ./postfix.SlackBuild
First, a safety precaution:

Code:

cp /etc/postfix/main.cf /etc/postfix/main.cf.dist
You need to set postfix up so that it can find its own aliases. Edit /etc/postfix/main.cf and add:

Code:

alias_maps = hash:/etc/postfix/aliases
alias_database = hash:/etc/postfix/aliases

Build the aliases database:

Code:

postalias hash:/etc/postfix/aliases
At this point, Postfix is already set up to send and deliver mail locally. Test it out.

Start Postfix:

Code:

/etc/rc.d/rc.postfix start
In one terminal:

Code:

tail -f /var/log/maillog
And in another:

Code:

mail USERNAME
Now you're ready to set Postfix up to relay mail to GMail. Start by setting Postfix to only accept mail from the local machine, with the following setting in main.cf:

Code:

mynetworks_style = host
The main.cf settings for turning on security (when connecting as a client) and enabling support, specifically, for GMail's SMTP server, are the same as the ones on innumerable blogs, such as this one: Postfix: Configuring Gmail as Relay:

Code:

relayhost = [smtp.gmail.com]:587

#  use tls
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 CAs to trust when verifying server certificate
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

# eliminates default security options which are imcompatible with gmail
smtp_sasl_security_options =

Then you add your SMTP login credentials to /etc/postfix/sasl_passwd:

Code:

[smtp.gmail.com]:587 username:password
Tell Postfix to recognize the credentials, and restart it:

Code:

postmap /etc/postfix/sasl_passwd
/etc/rc.d/rc.postfix restart

Fire up "mail" again, and send an email to a test address. It should arrive, and the maillog should show that it was routed through GMail.

Finally, set /etc/rc.d/rc.local to run Postfix on boot:

Code:

if [ -x /etc/rc.d/rc.postfix ]; then
    /etc/rc.d/rc.postfix start
fi

Success!

UPDATE:

And of course, imediately after writing that, I found out that it was better to just use ssmtp. Here's one blog entry on it: http://www.volcanic.co.uk/ruby-on-ra...-smtp-servers/

Richard Cranium 03-09-2014 05:47 PM

No, that would be a reason to start a new thread instead of bringing an almost 4 year old thread back to life.

I don't know about you, but when I ask "How do I get X to do Y?" an answer of "Well, Z does Y this way..." is a waste of my time. If I had wanted to know that, I would have asked "What's the best way to do Y?".

dugan 03-09-2014 06:34 PM

Quote:

Originally Posted by Richard Cranium (Post 5131728)
I don't know about you, but when I ask "How do I get X to do Y?" an answer of "Well, Z does Y this way..." is a waste of my time. If I had wanted to know that, I would have asked "What's the best way to do Y?".

I don't agree with that. I personally think it's a good policy to treat all "How do I get X to do Y?" questions as actually asking "What's the best way to do Y?". The exception is when there are clear indications that nothing other than X will do.

And in this case, I obviously know why the question was asked.

Quote:

No, that would be a reason to start a new thread instead of bringing an almost 4 year old thread back to life.
Perhaps. But I think that having both the Postfix and Sendmail howtos in one thread will be convenient for people who search for this subject in the future.

tronayne 03-10-2014 09:33 AM

While you guys are talking about the relative merits of sendmail and postfix, I have question: I have HughesNet, no fixed-IP, no access from the outside world to my LAN (it's not allowed) and no viable alternatives; I live in the boonies in northeastern Michigan, no cable, no light pipes, no nuthin'. I also have a DSpace server (not here, on cable down the road a ways but, nope, you can't have a fixed-IP address and you can't get in from the outside, it's LAN only).

DSpace wants to send mail to users and it can on a LAN with sendmail. No problem. A couple of PHP web pages want to do the same thing, no problem on the LAN but mail bounces from gmail.com because of the send address being a LAN address. And DSpace wants a SMTP server. From Thunderbird, no problem. From sendmail, problem.

I don't want to add another layer of software; e.g., postfix that I have to maintain, I want to use the standard stuff that comes with Slackware; e.g., sendmail, that'll be enough fiddling and twiddling.

So, reading though the old part of this thread, it looks like setting up sendmail to do the job is feasible (although I tend to agree with the comments about one SMTP server to another SMTP server).

What would be the best way, without adding a bunch of software, to get sendmail to, say, gmail? Not, mind, just for me to do but for somebody else to do if I drop dead tomorrow?

dugan 03-10-2014 11:28 AM

troynayne, if DSpace allows you to set the path to the sendmail binary (as PHP does; it's in php.ini), then use ssmtp. If it requires Sendmail to be running as a server, then see granth's post.

The ssmtp SlackBuild on SBo currently builds ssmtp without SSL support, which obviously doesn't work. I've found a patch to get it to build with SSL support on non-Debian systems, and I've asked the maintainer to apply it.

dugan 03-10-2014 02:02 PM

The question was never how to get Sendmail to relay mail through gmail; it was how to get PHP to relay mail through gmail.

I've updated my LEMP on Slackware guide with what I now think is the best solution.

Set PHP up to send mail through msmtp, and msmtp to send mail through GMail. Unlike, its competitors (like ssmtp), msmtp is still maintained.


All times are GMT -5. The time now is 06:21 PM.