From within a python program, I am trying to send an email message using this command: os.system('/home/pi/emailstart.sh')

The emailstart.sh program is

echo "Motion Started" | mail -s "Subject" [email protected]

This program sends the mail when I send it from the command line but does nothing when I try to send it from within there python program.

Any observations?

  • It should be #!/bin/bash
    – eftshift0
    Commented May 17, 2018 at 16:36
  • I wonder if when running python stuff, environment variables like $PATH are set up. Can you try providing full paths to echo and mail binaries?
    – eftshift0
    Commented May 17, 2018 at 16:38
  • Ah ha, It should be os.system('./home/pi/emailstart.sh')
    – Gary Payne
    Commented May 17, 2018 at 16:45

2 Answers 2


As an alternative to calling bash scripts from Python you can have a look at Python's smtplib.


You will need access to an SMTP server to send mail over the Internet. If your RPi doesn't have an SMTP server set up and working already, you may wish to consider using an external server. One popular choice is Google mail. If you have a Google email account, they will allow you to forward mail through their server. There is a GitHub page that will show you how to use Gmail as an SMTP service, and also has a small Python program that sends email messages on command; feel free to modify it for your purposes. Let us know if you have questions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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