Adding Email



Having the picam on a hanger roof is great, except.....

when it starts  to go wrong, I cant see what the issue is... 

Also, we are getting intermittent periods of 'no updates', and cant tell if these are because the husbos internet is down, the picam is sick, power cut etc etc...

So I thought it would be good if the picam sent a daily email, with a log file of its attempts during the day, so we can at least get an idea of what problems its seeing..

Also, because I'm using DHCP, its somewhat tricky to connect to the picam on the local wlan, as I dont know the ip.. So it would be good if it sent an email on startup telling me its new ip address..

To do this needs email, ( not installed by default ), and it would be good if it could use gmail, rather than our ISP email server... It was a lot easier to get working than I thought !

I followed this guide..


and this



then installed Mutt, so I could send attachments..

Tho actually, I’ve now found I can  stick my attachments in as the body of the email.
 
If you don’t fancy the links, I think the exact commands and order was..

sudo apt-get update
sudo apt-get install ssmtp
sudo apt-get install mutt

then configure the /etc/ssmtp/ssmtp.conf file to your gmail settings,
( I created a new gmail account for this )
just these bits..

AuthPass=Your-Gmail-Password


And away you go !

You can then send emails from cmd line and hence from a bash script..

Either using ssmtp

echo "this is a test" | ssmtp -s Subject schwabinger@blabla.de

or mutt


echo "Picam1 logfiles “ | mutt -a "/home/pi/picam1.log" -s "picam1 logfiles "$taken -- toby@home.com


the ‘echo’ bit is what appears in the body of the email
the –a bit is to add an attachment
the –s is the subject….

Here’s the script to do from a cronjob etc…


#!/bin/bash
# script to email logfiles to toby
# then delete the logfiles to save space

# get the single digit of time, ie 0-9 for file extension
day=`date "+%a"`
DMY=`date "+%x"`
now=`date "+%R"`
taken=$day"_"$DMY"_"$now

gettime=`date "+%M"`

{
cat /home/pi/picam1.log
} | mutt -a "/home/pi/picam1.log" -s "picam1 logfiles "$taken -- toby@home.com

rm -f /home/pi/picam1.log




No comments:

Post a Comment