I've been sending emails from the command line of my Raspberry Pi with this
echo “Body text” | mail -s Subject targetperson@example.com
code. How would I put this in an executable python file?
Thanks.
I've been sending emails from the command line of my Raspberry Pi with this
echo “Body text” | mail -s Subject targetperson@example.com
code. How would I put this in an executable python file?
Thanks.
This should work comment below if it doesn't I'll delete:
import os
os.system('echo “Body text” | mail -s Subject targetperson@example.com')
Put the following in a file called 'send_email'
#!/usr/bin/python
import sys
import os
address = sys.argv[1]
subject = sys.argv[2]
message = sys.argv[3] # Probably want to do some escaping on this and subject
os.system('echo "%s" | mail -s "%s" %s' % (message, subject, address))
Put this file on your PATH and run the following to make it executable:
chmod +x send_email
Now you should be able to send an email as follows:
send_email foo@bar.com "Important Subject" "Here is a message"