Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use remote SMTP via nullmailer and it requires set From field to the specific name, but cron set it as

How could I change it to something like

share|improve this question

migrated from Mar 10 '10 at 14:55

This question came from our site for professional and enthusiast programmers.

Which cron implementation (and OS)? – Kimvais Mar 10 '10 at 11:21
See this question:… for another solution. – robin Oct 23 '12 at 16:24
up vote 12 down vote accepted

I don't think you can change the FROM address, (someone should add a MAILFROM option).

You can do something like this though to achieve a similar result:

* * * * * /path/to/script 2>&1 | mail -s "Output of /path/to/script" -- -r "" -F"Full Name of sender"

All output is piped to the mail command so the MAILTO variable isn't used at all.

The to address would need to be set but you may be able to use $MAILTO variable. The -- sets the rest of the options to be sendmail options so you can use the -r and and -F options.

-s is the subject

-r is the reply address

-F is the Full name of the sender (makes it look nice in email clients)

share|improve this answer

Modern versions of cron do accept "MAILFROM=..." in the crontab format. I suggest that you try "man 5 crontab". If it mentions MAILFROM, your version should support it. The phrase to look for is towards the end of the paragraph discussing MAILTO, and should be something like this:

If MAILFROM is defined (and non-empty), it will be used as the envelope sender address, otherwise, ''root'' will be used.

share|improve this answer
Where "modern" means what? This is not supported by the most recent version of cron in Debian unstable (3.0pl1-124) from what I can see in the changelog or the documentation. – Flimzy Dec 24 '12 at 20:56
thx, this worked for me on Archlinux. There are many different flavours of cron. Debian's ISC is from 2004, so stretching the definition of "modern", but with no info on what system it's being used on - hard to provide that detail! – RuiDC Aug 26 '13 at 12:57
Unfortunately, Ubuntu's cron (at least as of 14.04 LTS) has no mention of MAILFROM in man 5 crontab. – Arto Bendiken Nov 13 '14 at 17:18
You can install cronie to replace cron on Debian/Ubuntu. Ta-daa: MAILFROM exists: – Andreas Klöckner Sep 16 '15 at 14:02
cronie doesn't exist on Ubuntu 16.04 – alex k May 13 at 8:33

You can set the nullmailer from address via environment variables or command line. The command line arguments are -f and -F for sender address and full name respectively.

Usually you can set environment variables in the crontab.


5 0 * * * /usr/local/bin/
share|improve this answer
He's asking about FROM: not TO: – Kimvais Mar 10 '10 at 12:15
Hm, this does not work for unknown reason. – Alexander Artemenko Mar 15 '10 at 6:46

/etc/mailname contains the domain name part of the FROM address. If /etc/mailname contains '' then cron running for root would have sender as

share|improve this answer
Some info here: - does not say if nullmailer use it. I use sendmail and it did not seem to work for it. – Zitrax Jan 30 '15 at 14:24

See this question if using Exim:

exim: Rewrite "From" header to envelope "FROM"

It should set the "From" address to the cronjob owner's. You can replace $header_from: with your custom address if you'd like to hard-code it to something else.

share|improve this answer

Another simple alternate is to use mutt,

  • create a .muttrc in the home directory of the user that runs cron with the following

    set realname="Joe User" set from="user@host" set use_from=yes

  • Run a script with mutt command in it or pipe the cron command to mutt from to send email.

Before mutt sends and email, it will set the From header from the .muttrc file.

share|improve this answer

For me, the easiest way to change the from address on a system, is to create a ~/.mailrc file with contents like this:

set name="My Full Name"
set from=""

Any of the mail commands that run as my user, now use these settings.

share|improve this answer

it is mailed from the user@domain -- the user is the login name the cron is running under -- so you'd have to create a user 'me' -- and run the cron job as that user.

Then to change the domain, there are different possibilities -- it could be that you need to change the hosts file entry (or, as on my machine, when I was configuring this -- an ubuntu box) -- change /etc/mailname -- to be the domain you want it to come from.

share|improve this answer
This isn't actually true--at least not in many cases. On my system, for instance, it is only sent from 'user', not 'user@domain'. It is the responsibility of the MTA to add the local domain name. This is significant in some cases (such as mine) where my MTA (for reasons too complicated and boring to describe) is not adding the domain name. – Flimzy Dec 24 '12 at 21:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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