≡ Menu

Linux / UNIX: Change Crontab Email Settings ( MAILTO )

I would like to send an email to user@example.com instead of default system root user for crond service on a Linux or Unix-like system. How do I change the email settings under crontab file on a Linux or Unix-like systems?

A crontab file contains instructions to the cron daemon. It wakes up every minute, examining all stored crontabs, checking each command to see if it should be run in the current minute. When executing commands, any output is mailed to the owner of the crontab or to the user named in the MAILTO environment variable in the crontab, if such exists. The syntax is:

name = value

Where the spaces around the equal-sign (=) are optional, and any subsequent non-leading spaces in value will be part of the value assigned to name. The value string may be placed in quotes (single or double, but matching) to preserve leading or trailing blanks. The value string is not parsed for environmental substitutions, thus lines like:


will not work as you might expect.

MAILTO Variable

In addition to LOGNAME, HOME, and SHELL, cron will look at MAILTO if it has any reason to send mail as a result of running commands in "this" crontab. If MAILTO is defined (and non-empty), mail is sent to the user so named. First open your crontab file:
# vi /etc/crontab
$ crontab -e
To send email to vivek@nixcraft.in, enter:

If MAILTO is defined but empty (MAILTO=""), no mail will be sent.

Otherwise mail is sent to the owner of the crontab.

{ 17 comments… add one }

  • Brock Tice September 20, 2008, 2:17 pm

    Thanks, never even thought it could be changed, I always used my .forward for this. Very handy.

  • Darren September 20, 2008, 8:40 pm

    I too have always the “.forward” option. This is done by the follwing…..

    create a new file called .forward
    vi /root/.forward

    Enter the email address on the first line in the file.

    Save (w) the file and exit (q)

    Now, anytime the ‘root’ user get an email, it will automatically be forwarded to the address you specified in the .forward file.

    You can also place the .forward file in users home directories /home/user1/.forward

    Thanks for the info up above though, I’ll have to check that out.

  • phanikumar November 26, 2008, 6:08 am

    Hi All,

    Please help me out..

    I configured cron job under FTPPKR user.i’ll get mails from FTPPKR@xyz.com whenever cron runs..But whenever i need the mails to be delivered from GTPPKR@xyz.com user.

    Is it possibe? If yes, please help me out..

  • Andre July 4, 2009, 8:15 am

    Yes, that’s entirely possible. Just figure out if the emails are being sent with sendmail or postfix, then adjust their settings to reflect that. You could deploy address rewrites to achieve this, for example.

  • maxo May 7, 2010, 7:48 pm

    SOLARIS does not support the MAILTO feature. Instead one needs to append the crontab entry with | mailto user@domain
    00 12 * * * run_command.sh | mail user@domain

  • Dmitri Minaev September 1, 2010, 5:25 am

    Mail addressed to ‘root’ is often redirected to some other account using /etc/aliases. You might like to edit (or add) the line beginning with ‘root:’ to point to some other account.

  • alex July 3, 2011, 2:33 am

    But, How if I dont want to receive notification from crontab? How to set it ? Because I’m monitoring mail server, and notification from crontab unnecessary for me.

  • martijn July 14, 2011, 6:02 am

    @alex: add >/dev/null 2>&1 to the end of your line(s) in crontab. This will redirect all crontab output to /dev/null

  • mehturt July 26, 2011, 3:42 pm

    What command is cron using to send email? I’m trying to get cron working with esmtp, but no luck so far.

  • Alwin Doss January 23, 2013, 10:20 am

    I wanted to know under what circumstances will the email be sent.
    Is it only when cron encounters a warning or error
    Or even when the commad is executed succesfully

  • Pankaj June 4, 2013, 6:22 am

    I am new for cronjob so help me.
    How to send a automatically mail to fix mail address .

  • Irfan July 2, 2013, 7:39 am


    While using cronjob when my cronjob fails then the mail is sent to the user who is login but not to mailto user. What is required to send mail to the “mailto” user even when the test fails.

  • Sebastian May 28, 2014, 7:59 am

    I’ve setted up a new cron (rsync job), the first few days it mades errors which I get by email. Now it looks to work fine, but I don’t get an email. Someone knows why?

    thanks in advance

    • Nix Craft May 28, 2014, 9:54 am

      Check your server mail log file. Also, check your spam folder.

      • Sebastian June 2, 2014, 2:04 pm

        Email with errors I receive. So I guess there is no try to send an email.

  • ramses June 21, 2014, 1:00 pm

    i have this line in crontab could someone explain me what is the mean of this?
    thanks by advance
    #*/1 * * * * root /usr/local/rtm/bin/rtm 26 > /dev/null 2> /dev/null

    • mhmhI.mstfa June 1, 2015, 8:04 am

      this will run the /usr/local/rtm/bin/rtm script once every minute and redirects the output messages to /dev/null so as to get rid of them

Leave a Comment

   Tagged with: , , , , , , , ,