WebFaction
Community site: login faq

I've set MAILTO in my crontab so that output from my cron jobs is sent to my email address, but the messages arrive from "unknown sender".

How do I specify the sender address for email sent from my cron jobs?

asked 26 Dec '12, 13:14

seanf's gravatar image

seanf
12.1k21635
accept rate: 37%


There are two ways you can specify the sender address for your cron email messages:

The MAILFROM variable

You can set a MAILFROM variable in your crontab, like this:

MAILFROM=sender@mydomain.com
MAILTO=recipient@mydomain.com

* * * * * some_cronjob_goes_here 2>&1

With these settings, any output from your cron jobs will be sent to your MAILTO address, using your MAILFROM address as the sender.

Note that this applies to all of your cron jobs. If you want to use different mail settings for individual cron jobs, then use the "pipe to the mail command" method, described below.

Pipe to the mail command

If you want to use mail settings different from your MAILTO and MAILFROM variables for a specific job, then you can specify your sender and recipient addresses by piping the output of individual cron jobs into the system mail command, like this:

* * * * * some_cronjob_goes_here 2>&1 | mail -s "message subject here" -S from=sender@mydomain.com recipient@mydomain.com
permanent link

answered 26 Dec '12, 13:15

seanf's gravatar image

seanf
12.1k21635
accept rate: 37%

edited 23 Mar, 09:58

iliasr's gravatar image

iliasr ♦♦
1.8k14

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×257
×81

question asked: 26 Dec '12, 13:14

question was seen: 23,579 times

last updated: 23 Mar, 09:58

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2016 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM