Outstripping all other read posts 5 to 1 is the motion detection post I did at the end of June. For those who haven’t seen it before you can read it here.
In the original post I sent a message via SMS to my phone to alert me that there was motion detected. That’s fine, some folk want to be emailed especially via their GMail accounts. That’s okay too…..
The change is quite simple:
import smtplib def sendEmail(): username = "xxxxxx" password = "xxxxxx" FROM = "firstname.lastname@example.org" TO = ["email@example.com"] SUBJECT = "Testing sending using gmail" TEXT = "Motion was detected from the Raspberry Pi" message = """\From: %s\nTo: %s\nSubject: %s\n\n%s """ % (FROM, ", ".join(TO), SUBJECT, TEXT) try: server = smtplib.SMTP("smtp.gmail.com", 587) #or port 465 doesn't seem to work! server.ehlo() server.starttls() server.login(username, password) server.sendmail(FROM, TO, message) server.close() print 'successfully sent the mail' except: print "failed to send mail"
This method connects the GMail SMTP server and with the user’s username and password details logs on and sends an email.
Like the SMS you have to be careful not to send too many emails from the Pi, you don’t want to upset Google.
I’ve both version of the code on the RPIMotion Github repo.
4 responses to “Raspberry Pi Motion Detection revisited. #Pi #sensors #pir”
Thank you very much.I appreciate you taking the time to share this
I have made something similar using push bullet
oh added a way to tweet it also 🙂
Thanks Jase it worked for me first time. I hook things up via dupont cables to avoid the need for a breadboard.