mailto crontab doesn't work
Asked Answered
H

3

26

I'm running a script on my mybookworld(NAS) via crontab every day. And it would be nice if it could send me everyday an email report with the output of the script.

So I looked at MAILTO in crontabs, but it doesn't send me anything at all. The script ran correctly at the right time, but there was no email. This is my crontab:

~ # crontab -l
[email protected]

0 0 * * * python /root/erepCrawler/src/main.py

I've written a "smaller" crontab for testing reasons:

[email protected]
* * * * * echo "blaah"

This should send me every minute an email with "blaah" as the body. If I'm wrong please correct me.

Is there another package needed for sending mails with crontab? sendmail is installed in /opt/sbin/sendmail.

Helbonia answered 25/3, 2011 at 17:53 Comment(3)
I guess you didn't set up any mail transport agent appropriately, did you? Can you send mails from command line, e.g. echo Test | mail -s Test [email protected]Campo
i think you are right. There is not even installed something named mail. After a bit of googling i'm trying now to install postfix on the Nas. With this, i should work right?Helbonia
If postfix is configured correctly (expecially relay server etc.) it should work.Campo
R
14

It should work in the cron with following modifications:

MAILTO="[email protected]"
* * * * * echo blaah

works on my server, just tested.

Rambert answered 25/3, 2011 at 23:4 Comment(6)
Well, i think the " isn't the point (see bml's comment). But it is good to know, that the echo "blaah" works if the mail thing is installed correctly:) thanks for the helpHelbonia
are the quotes needed? I am trying to debug my problem.Byrnes
Quotes not needed, the following is perfectly valid [email protected],[email protected]Legault
Quotes needed for no email! Took quite a while to figure out.Marty
I did tried without quotes and It works as all email users received the email. In my case, it wasn't working because I was emailing the output and trying to write it to a file at the same time which means the following code, it won't work. [email protected],[email protected] * * * * * echo 'blah' >> /tmp/logs/blah.logHindenburg
You need to have a working MTA (mail transport agent) installed and configured for the MAILTO to work properlyTeador
S
2

after spending hours debugging why this wasn't working with nullmailer on my Debian box, I discovered I had a filter at gmail sending everything from cron to "All Mail" without going through my inbox... just something to check.

Suannesuarez answered 8/9, 2016 at 7:58 Comment(0)
J
1

I had to add this to /etc/hosts so that mail to anyone at my server's own FQDN would be resolved:

127.0.0.1 mydomain.com.

Notice the dot at the end. In my case, I'm sending email essentially to root@localhost with MAILTO=root which gets translated to [email protected].

Here's some more detail on this answer.

Josiahjosias answered 16/8, 2017 at 18:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.