I have python script which sends email by shell function "mail". It runs fine. However, when I put in crontab to run it is unable to send mail to the recipient, rather it sends error message to my address. Is there any issue that crontab cannot send mail running via another script?

Here is my crontab entry:

30 8 * * * /home/akand/./pyscript.py

The pyscript.py has

import os  
os.system(''' mail -s "Message" [email protected] <<< "Please 
check ..." ''')  

As I mentioned, pyscript.py runs fine.

  • 1
    Please edit your question to include the crontab entry that you are using.
    – Kusalananda
    Apr 10, 2018 at 15:11
  • Although I have edited tags, it doesn't show, at least not from my end.
    – Akand
    Apr 10, 2018 at 15:38
  • You have an issue with your cron job and to see what the issue is, we would need to see what your crontab entry looks like. Please add the output of crontab -l (or just the specific entry) into the text of the question.
    – Kusalananda
    Apr 10, 2018 at 15:40
  • 1
    What's the error message? Is it an empty body or recipient? You may have an interactive environment variable that's not being set by cron.
    – Jeff Schaller
    Apr 10, 2018 at 16:09
  • In dead.letter following is produced: To: found, not, command, [email protected] Subject: Message: ...... User-Agent: Heirloom mailx 12.4 7/29/08 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit
    – Akand
    Apr 10, 2018 at 16:40

1 Answer 1


As Jeff mentioned, the environment variable was not passing. The command in crontab:

30 8 * * * $HOME/.bash_profile; /home/akand/./pyscript.py  


  • I would have understood that it would work with . "$HOME/.bash_profile", but as you have written it now, it just runs .bash_profile as a script. That means that the environment variables are not passed on to the Python script.
    – Kusalananda
    Apr 11, 2018 at 15:26
  • If I understand well, the pyscript.py is in my home directory, that's the reason I do not need to specify <. "$HOME/.bash_profile" >
    – Akand
    Apr 11, 2018 at 15:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .