Send email using command line on Linux Raspberry Pi
I normally use sendemail on my Rasberry Pi because it’s easiest way to send email from your Raspberry Pi Linux machine using command line. Let’s first install sendemail:
apt-get install sendemail
Using sendemail is easy:
sendemail -xu LOGIN -xp PASSWORD -f FROM -t TO -s SERVER:PORT -o tls=yes -u "SUBJECT" -m "MESSAGE" -a ATTACHEMENT FILE
You might not need -xu, -xp or tls=yes but I have used those just to be sure. So my typical sendemail line is pretty much like this:
sendemail -xu LOGIN@gmail.com -xp PASSWORD -f my@email -t TO -s smtp.gmail.com:587 -o tls=yes -u "Test" -m "Just testing" -a /scripts/myscript.sh
When I’m not sure if my scripts/raspberry pi is working perfectly I use to add scripts as attachement so I easily have at least one working copy of my script and different versions of it at the same time.
Now we can use this with earlier scripts example with IP scripts we can add this line to good place on that script:
sendemail -xu LOGIN@gmail.com -xp PASSWORD -f my@email -t TO -s smtp.gmail.com:587 -o tls=yes -u "RasPi IP" -m "Your Raspberry Pi new IP address is $ip2"
If your sendemail says:
Sep 13 06:33:08 raspberrypi sendemail[16329]: ERROR => No TLS support! SendEmail can't load required libraries. (try installing Net::SSLeay and IO::Socket::SSL)
It should start to work if you install libio-socket-ssl-perl:
apt-get install libio-socket-ssl-perl
This has helped every time when I have had this problem.
Leave a Reply