mailto in crontab help needed

Asked by petermat

I read that cron will send an email on completion of a task on a crontab. My eddress is entered under my log on name, and I have
MAILTO=peter
where "peter" is my log on name, as the first non comment line in my crontab. But I don't get any emails though cron has obviously done a task - I did not get one before I added the mailto line either. What am I doing wrong?

I am running ububtu 10.10

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu cron Edit question
Assignee:
No assignee Edit question
Solved by:
Luky Winarto
Solved:
Last query:
Last reply:
Revision history for this message
actionparsnip (andrew-woodhead666) said :
#1

You could use something like this:

cat file | mail <email address hidden>

May work.

Revision history for this message
petermat (petermat) said :
#2

Fraid not - got an error message directly -

bad minute errors in crontab file, can't install.

removing the line allowed saving error free.

But why does crontab comment explicitly say I will get an email by default, and the man page says this is true, but MAILTO also works (but without defining its syntax) - but I don't get anything? Surely this means I have something set up incorrectly outside of crontab?

Peter

Revision history for this message
Luky Winarto (luckyborneo) said :
#3

Hello Petermat,

You have to setup an email server.
Perhaps I can assist you.

First, install ssmtp package:
sudo apt-get install ssmtp

Then edit /etc/ssmtp/ssmtp.conf:
sudo nano /etc/ssmtp/ssmtp.conf
<email address hidden>
mailhub=smtp.gmail.com:587
rewriteDomain=
<email address hidden>
UseSTARTTLS=YES
AuthUser=username
AuthPass=password
FromLineOverride=YES

Then add each account that you want to be able to send mail from by editing, ‘/etc/ssmtp/revaliases‘:
root:<email address hidden>:smtp.gmail.com:587
localusername:<email address hidden>:smtp.gmail.com:587

You can send an email by type:
sudo ssmtp <email address hidden>

If you succeded then you can configure crontab
crontab -e
<email address hidden>

Have a nice try...

Revision history for this message
petermat (petermat) said :
#4

Luky - thanks for all that - I will have a go. Obviously I have to do some editing on the eddress, which is generally not a problem, for example I will translate

root:<email address hidden>:smtp.gmail.com

into

root:<email address hidden>:smtp.pathcom.com

 - but what is the significance of the ":587" and do I append that literally?

Also, in sending the trial email should I use

sudo ssmtp <email address hidden> ?

and for the crontab

<email address hidden>

Revision history for this message
Luky Winarto (luckyborneo) said :
#5

Hi Petermat,

<email address hidden>:smtp.gmail.com:587

':587' is the smtp port for gmail using STARTTLS, so if your email server 'smtp.pathcom.com' using standart smtp port which is port 25, you have to change like this:
root:<email address hidden>:smtp.pathcom.com:25

On /etc/ssmtp/ssmtp.conf, you can remove the line 'uses STARTTLS'

Then, when you trial to send an email, just open your terminal program then type:
sudo ssmtp <email address hidden>

You will then type your message, hit enter and ‘ctrl+d‘
Have a nice try...

Revision history for this message
petermat (petermat) said :
#6

furthermore!!

When I did

sudo apt-get install ssmtp

I got asked for password , then "reading..." , "building ...", "reading....", "Unable to locate package ssmpt"

so stopped at the first step!

Revision history for this message
petermat (petermat) said :
#7

Sorry forget last - I cannot spell.

Revision history for this message
Luky Winarto (luckyborneo) said :
#8

Something wrong with your software sources.
Would you mind give us the output of this command:
cat /etc/apt/sources.list

Copy all the output and then paste here...
Look forward for your information..

Revision history for this message
petermat (petermat) said :
#9

furthermore!!

When I did

sudo apt-get install ssmtp

I got asked for password , then "reading..." , "building ...", "reading....", "Unable to locate package ssmpt"

so stopped at the first step!

Revision history for this message
petermat (petermat) said :
#10

Sorry about the crossover of info!

OK so I have gone all the way through, but something is adrift. If I type

sudo ssmtp

I properly get an error message saying I did not supply a destination, so ssmtp is installed OK.

If I type

sudo ssmtp <email address hidden>
I (sometimes) get asked for my password by sudo, and then can type a message OK. However Ctrl-d did not get me out - did not appear on screen either. I had to Ctrl-z to get out.

I will check all my edits tomorrow - I have to go now - but will let you know.

One thing, when you say "AuthUser=username" "AuthPass=password" I am assuming these are the ubuntu username and password?

Revision history for this message
Luky Winarto (luckyborneo) said :
#11

Try this trick:
sudo mv /etc/apt/sources.list /etc/apt/sources.list.backup
sudo nano /etc/apt/sources.list

Then copy all these lines:
deb http://archive.ubuntu.com/ubuntu/ maverick main universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ maverick main universe multiverse
deb http://archive.ubuntu.com/ubuntu/ maverick-updates main universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ maverick-updates main universe multiverse
deb http://archive.ubuntu.com/ubuntu/ maverick-security main universe multiverse
deb-src http://archive.ubuntu.com/ubuntu/ maverick-security main universe multiverse

Save and then run:
sudo apt-get update && sudo apt-get install ssmtp

Please give it a try... let's see what happen..

Revision history for this message
Best Luky Winarto (luckyborneo) said :
#12

Oh.. I'm really sorry, it looks like you already install ssmtp package properly.

Okay... about your questions,
"AuthUser=username" "AuthPass=password"
You have to fill with your email username and email password.

Good luck, Petermat.. looking forward for your information... have a nice work!

Revision history for this message
petermat (petermat) said :
#13

Checked the edits are OK, at least to my understanding, and changed the AuthUser and AuthPass per last post. Still get no response to Ctrl+D

However, I am thinking that I am getting into trouble because I have a cross linked eddress, i.e. my ISP (telus) routes my email via a previous ISP (pathcom) so I did not have to change my eddress. So I am going to simplify and go via just one email provider - like your original gmail version. Clearly ssmtp is basically working, so I think we will call the Linux issue solved whilst I sort out the double server issue.

Thanks for the help!.
Petermat

Revision history for this message
petermat (petermat) said :
#14

Thanks Luky Winarto, that solved my question.