I use remote SMTP via nullmailer and it requires set From field to the specific name, but cron set it as [email protected].
How could I change it to something like [email protected]?
I use remote SMTP via nullmailer and it requires set From field to the specific name, but cron set it as [email protected].
How could I change it to something like [email protected]?
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:
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:
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)
/etc/mailname contains the domain name part of the FROM address. If /etc/mailname contains 'somecompany.com' then cron running for root would have sender as [email protected]
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.
For me, the easiest way to change the from address on a system, is to create a
~/.mailrc
file with contents like this:Any of the
mail
commands that run as my user, now use these settings.Here are few things you can apply to change your sender domain:
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.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.
I had to change
/etc/mail/sendmail.cf
and/etc/mail/sendmail.mc
, because/etc/mailname
wasn't used. It only changes the from domain though, not the user.In my case, I followed these steps to resolve the issue:
set the value of this variable:
uncomment this line: