You are not logged in.

#1 2010-03-02 17:46:07

Nergar
Member
Registered: 2007-11-03
Posts: 15

Configuring cron to use google's SMTP server? [Solved]

Well, I have a problem, my ISP is blocking port 25 so I can't send any emails through that port.

So I thought maybe it would be possible to configure cron to send email messages using google's SMTP server but I don't know where to begin.

Ok, so is it possible or am I chasing a silly dream? Should I just write a shell script that sends email depending on the return code of a program instead of relaying on cron's ability to send emails?

Last edited by Nergar (2010-03-03 06:55:47)

Offline

#2 2010-03-02 18:30:37

ataraxia
Member
From: Pittsburgh
Registered: 2007-05-06
Posts: 1,553

Re: Configuring cron to use google's SMTP server? [Solved]

You should instead probably configure your MUA (postfix, exim, msmtp, whatever) to send the mails through google's SMTP server. That way, anything on your machine that sends mails will automatically use it. The bad part is that you have to put your Google name and password in plain text in a config file.

Offline

#3 2010-03-02 21:31:11

CountDuckula
Member
Registered: 2010-02-28
Posts: 151

Re: Configuring cron to use google's SMTP server? [Solved]

Just a thought, has your ISP blocked port 465 which is secure SMTP?

Offline

#4 2010-03-02 21:41:10

Nergar
Member
Registered: 2007-11-03
Posts: 15

Re: Configuring cron to use google's SMTP server? [Solved]

mmm, no, I don't think so. I'll have to check

Offline

#5 2010-03-02 22:06:05

sand_man
Member
From: Australia
Registered: 2008-06-10
Posts: 2,164

Re: Configuring cron to use google's SMTP server? [Solved]

What kind of filthy ISP blocks ports like that?


neutral

Offline

#6 2010-03-02 22:19:16

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Configuring cron to use google's SMTP server? [Solved]

Check also if they instead allow/use port 587 which is the submission port.

Google mail accepts connections on 25 and 587 (IIRC), so if they're both blocked by your ISP then no app will be able to send mail via gmail (or anyone else for that matter), unless I'm misunderstanding your post.

How do they expect you to send email?


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#7 2010-03-02 22:28:56

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Configuring cron to use google's SMTP server? [Solved]

ataraxia wrote:

You should instead probably configure your MUA (postfix, exim, msmtp, whatever) to send the mails through google's SMTP server. That way, anything on your machine that sends mails will automatically use it

//blue/0/~/ pacman -Q msmtp
msmtp 1.4.19-1
//blue/0/~/ cat .msmtprc
# msmtp config file

# gmail
account gmail
host smtp.gmail.com
port 587
protocol smtp
auth on
from pbrisbin@gmail.com
user pbrisbin@gmail.com
password XXXXX
tls on
tls_nocertcheck

# use gmail as default
account default : gmail
//blue/0/~/ cat .mailrc
set sendmail=/usr/bin/msmtp

but... as whom does cron run?

Offline

#8 2010-03-02 22:45:12

Nergar
Member
Registered: 2007-11-03
Posts: 15

Re: Configuring cron to use google's SMTP server? [Solved]

Well, the ISP is TELMEX, a Mexican ISP and it's only blocking port 25 as a counter measure for spam and computers infested with spambots. I also found out they will easily unblock that port if you call them and explain.

I have msmtp running and sending emails from standard input, now I need to know how to tell cron to use msmtp instead of whatever it is using. sendmail?

So, now I have two options;
The easy way out, call the ISP and get the port unblocked
Or the arch way, configure my system to behave exactly as I want wink

Offline

#9 2010-03-02 22:49:18

ataraxia
Member
From: Pittsburgh
Registered: 2007-05-06
Posts: 1,553

Re: Configuring cron to use google's SMTP server? [Solved]

Look at the -M and -m flags for crond.

Offline

#10 2010-03-02 22:50:29

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: Configuring cron to use google's SMTP server? [Solved]

I still don't understand (probably my fault here).
What port is msmtp using now to send emails, and why do you need to use cron?
Why not just get your MUA to use msmtp directly?

EDIT: does this link answer your question?
http://www.debianhelp.org/node/4600

EDIT2: from the crond man page:

 -M mailer
              When cron jobs generate any stdout or stderr, it's formatted as a mail message and piped to /usr/sbin/sendmail -t -oem -i.  Attempts  to  mail  cron
              output  are  also logged (regardless of whether they succeed).  This switch permits the user to substitute a custom mail handler or script.  It will
              be called with no arguments, and with the mail headers and cron output supplied to stdin.  When a custom mail handler is  supplied,  mailing  is  no
              longer logged (have your mail handler do that if you want it).  When cron jobs generate no stdout or stderr, nothing is sent to either sendmail or a
              custom mail handler.

EDIT3: beaten to it. Should've checked before posting, after reading around. smile

Last edited by skanky (2010-03-02 23:00:56)


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#11 2010-03-02 23:03:28

CountDuckula
Member
Registered: 2010-02-28
Posts: 151

Re: Configuring cron to use google's SMTP server? [Solved]

Nergar wrote:

Well, the ISP is TELMEX, a Mexican ISP and it's only blocking port 25 as a counter measure for spam and computers infested with spambots. I also found out they will easily unblock that port if you call them and explain.

I have msmtp running and sending emails from standard input, now I need to know how to tell cron to use msmtp instead of whatever it is using. sendmail?

So, now I have two options;
The easy way out, call the ISP and get the port unblocked
Or the arch way, configure my system to behave exactly as I want wink

I vote the easy way as its quick and it's a service you pay your ISP for.

Offline

#12 2010-03-03 00:12:12

Nergar
Member
Registered: 2007-11-03
Posts: 15

Re: Configuring cron to use google's SMTP server? [Solved]

Well, the easy way out is fine, but I rather work a little harder and learn a few things in the process.

As soon as I get home I'll check that link and those flags.

Offline

#13 2010-03-03 06:55:04

Nergar
Member
Registered: 2007-11-03
Posts: 15

Re: Configuring cron to use google's SMTP server? [Solved]

well, i think cofiguring the -M switch in /etc/conf.d/crond should do the trick, thanx all for the help.

Offline

#14 2010-03-04 17:13:14

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: Configuring cron to use google's SMTP server? [Solved]

Easiest is to make /usr/sbin/sendmail a symlink to /usr/bin/msmtp. If you prefer not to, then you could add "-M /your/mail/handler/script" to the dcron invocation line in /etc/conf.d/crond. If you use the -M route, the mail handler script will be called without arguments. If you use the sendmail-is-a-symlink route, msmtp will be called with the default arguments "-t" "-oem" and "-i". msmtp ignores all of these but "-t", I'm not sure whether msmtp will work if dcron calls it without the "-t" argument. But if you try "-M /usr/bin/msmtp" and you find that not working, this is the reason. You'll need to either supply a wrapper script to -M that calls msmtp with the "-t" switch, or use the sendmail-is-a-symlink solution.

Offline

#15 2010-03-04 17:26:28

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Configuring cron to use google's SMTP server? [Solved]

everyone seemed to miss this from my post:

//blue/0/~/ cat .mailrc
set sendmail=/usr/bin/msmtp

this makes my user's sendmail msmtp -- no symlink required.

now, my question is -- how to do it for cron? is /etc/mail.rc the same but system-wide? with fcron i just set the sendmail command in it's config so this is more of a curiosity then a call for help.

Offline

#16 2010-03-04 17:33:48

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: Configuring cron to use google's SMTP server? [Solved]

I have no idea about ~/.mailrc or /etc/mail.rc (and I'm the developer of dcron). dcron doesn't go around reading any user environment variables or dotfiles, in fact that's antithetical to its design. If you supply a -M handler, it calls it as the user in question, with no arguments and a formatted email as stdin. If you don't, it tries to call "/usr/sbin/sendmail -t -oem -i" as the user in question, with a formatted email as stdin. If the sendmail binary you have installed consults the user's .mailrc file and passes any input on to msmtp when it's configured as you described, then you may well be able to rely on that. But dcron's behavior is intentionally dumb, in the way I described.

Offline

#17 2010-03-04 18:47:17

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Configuring cron to use google's SMTP server? [Solved]

Profjim wrote:

If you don't, it tries to call "/usr/sbin/sendmail -t -oem -i" as the user in question.

i'm dumb.  i was so busy trying to think of how to create /home/cron/.mailrc that i forgot that cron runs commands as the user who's crontab it's reading from.  duh.

anyway, i just tested using the above command directly and it does not appear to respect my ~/.mailrc in anyway.  i must've been confusing my setup for mailx as a more general sendmail override -- it was a long time ago.

i.e.

    echo test | mail a@b.com # uses msmtp
    echo test | sendmail a@b.com # does not

anyways, sorry for the misinformation and thanks for the clarification.

Last edited by brisbin33 (2010-03-04 18:47:31)

Offline

Board footer

Powered by FluxBB