Feb 182013
 

I recently setup motion on my Raspberry Pi so I could stream a Logitech c110 to my Android phone. That was successfully setup in this post.

Next step was to start sending the snapshots to my email address when motion was detected. That way I could see if anything was being detected without having to log into the Raspberry Pi itself.

As I started off with RSE, there is no mail daemon installed, so that’s the first thing I need to do.
sudo apt-get install postfix

Configuration for postfix will depend on where you want email to be routed to. I will be sending it to GMail, and my ISP needs the mail to go through their mail server, so I selected Internet with smarthost
Next thing to setup is the local mail client. There are a few options, but in this post we will use heirloom-mailx.
sudo apt-get install heirloom-mailx

We can test out the Postfix install by attempting to send a test email with our newly installed mail client now !
echo 'hi' | mail -s Test <Your Email Address>
This will send an email to your email address with a body text of “hi” and the subject of “Test”.
If you receive it, congratulations ! Your Pi is now emailing out.
If not then you may need to check your junk mail to see if it got junked.
If there are any issues getting the mail out, running mail on the Pi will launch the mail client in which you will see any failed attempts to send an email.

Once Postfix and the local email client is setup, it’s time to configure motion.
If you’re only running one camera, in /etc/motion/motion.conf at approximately line 521, you should see this
; on_picture_save value
This is the line that configures what motion will do to a file once it is saved.

What we will do, is setup motion to attach the file to an email, and send it to your email address when motion is detected and a file is saved.
To do that, change line 521 to the following –
on_picture_save echo 'webcam alert' | mail -a %f -s "Webcam Alert" <Your Email Address>
Make sure you remove the ; at the beginning as that denotes a commented out line.
The ‘webcam alert’ text can be changed to whatever you want in your version.
Running mail with the -a command line argument will attach the file specified, in this case it is %f, which is motion’s variable for the saved file.

Once that is done, restart motion with /etc/init.d/motion restart and whenever you get motion detected, it will email you the picture as an attachment !

Share