0

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

#!/bin/bash
echo "Motion Started" | mail -s "Subject" kayak@cableone.net

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?

3
  • It should be #!/bin/bash
    – eftshift0
    May 17 '18 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
    May 17 '18 at 16:38
  • Ah ha, It should be os.system('./home/pi/emailstart.sh')
    – Gary Payne
    May 17 '18 at 16:45
2

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

1

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, privacy policy and cookie policy

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