9

This question already has an answer here:

I have added a cron job for my incremental backup, and I configured it like this:

0 23 * * * /usr/bin/rsync -ravzX /mnt/external/project/ /media/backup/project/ | mail -s "Backup Success" admin@example.com

But i didn't receive any e-mails.
How can I find out what's wrong?

marked as duplicate by MadHatter, masegaloeh, mdpc, HBruijn, Jenny D May 12 '15 at 9:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Check mail.log entry – masegaloeh May 11 '15 at 6:41
  • 1
    Can you send mail successfully using mail from the command line? – Paul Haldane May 11 '15 at 6:51
  • @paul: its working in mail command – Booth May 11 '15 at 7:01
  • @masegaloeh: no log entry – Booth May 11 '15 at 7:03
  • 3
    Check your cron log. – Jenny D May 11 '15 at 7:26
19

You can use the MAILTO option in crontab to define your email address and receive all output and errors in all crons running.

open crontab using

crontab -e

on the top of the file use MAILTO option as

MAILTO=email@example.com

cron looks for MAILTO feature to decide where it should send cron logs. it send is to root by default if the crons are running with root.

put it there on the top and remove any mail command reference from the crons.

Test and verify if you receive cron alerts after this.

  • My backup mail is in spam folder.Why it goes to spam?how to move it on inbox? – Booth May 11 '15 at 12:28
  • The email delivery is something you have to consider as per your requirements. If you are the only one who receives such email then simply mark that email as "Not Spam" and it will land in inbox next time. But if you are looking for a generic email solution that will deliver email in inbox then i recommend you must read the best practices like Setup a Reverse DNS record for your Server IP address, a PTR record , an SPF record that permits legitimate servers an outgoing email on behalf of that domain etc.. – sandeep.s85 May 11 '15 at 12:32
1

Problem in this case was that message had been delivered to spam folder on gmail (which is always worth checking). Adding sender as a contact should avoid this.

Apart from that, looking at the received message's full headers may give clues as to why it was flagged as spam (and so how to influence filtering not to do this).

-1

On FreeBSD

1: Check log:

tail -f /var/log/cron
tail -f /var/log/maillog

2: Replace sendmail with ssmtp vi /etc/rc.conf file.. and add:

sendmail_enable="NO"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"

3: Launch following commands:

killall sendmail
cd /usr/ports/mail/ssmtp/
make install replace clean

4: Edit ssmtp conf file:

vi /usr/local/etc/ssmtp/ssmtp.conf

.... and add following lines:

root=yourrealemail@example.com
mailhub=smtp.example.com:465
RewriteDomain=example.org
UseTLS=YES
AuthUser=user@example.com
AuthPass=password222
FromLineOverride=YES
Hostname=yourhostname

5: Enter following command:

echo ‘ssmtp_enable=“YES”’ >> /etc/rc.conf

p.s. other explained options of ssmtp.conf are here:

http://www.techrepublic.com/blog/it-security/use-ssmtp-to-send-e-mail-simply-and-securely/

  • 12
    This would have been a great answer if the question had been "How do I get SSMTP to send mail via gmail on FreeBSD". Unfortunately, the question is about cron & mail on Linux. – Jenny D May 11 '15 at 7:27
  • What exactly was the OP's question: "How can I send an email after a cron job?", or "How can I find out what's wrong (with my mail setup)?" – user305964 Dec 10 '16 at 16:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.