Your SlideShare is downloading. ×
Raspberry Pi - Sending an E-mail
Raspberry Pi - Sending an E-mail
Raspberry Pi - Sending an E-mail
Raspberry Pi - Sending an E-mail
Raspberry Pi - Sending an E-mail
Raspberry Pi - Sending an E-mail
Raspberry Pi - Sending an E-mail
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Raspberry Pi - Sending an E-mail

15,167

Published on

When the Raspberry Pi is used in monitoring applications it can be useful if it can alert you when a particular event occurs. For example, when a sensor indicates that the temperature has fallen below …

When the Raspberry Pi is used in monitoring applications it can be useful if it can alert you when a particular event occurs. For example, when a sensor indicates that the temperature has fallen below a certain level, the Raspberry Pi can alert you by e-mail.

Published in: Technology, Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
15,167
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. RASPBERRY PISending an e-mail from a Python scriptwww.sf-innovations.co.uk
  • 2. When the Raspberry Pi is used in monitoring applications it can beuseful if it can alert you when a particular event occurs. Forexample, when a sensor indicates that the temperature has fallenbelow a certain level, the Raspberry Pi can alert you by e-mail.Step 1Make sure that all everything is up to date by using the apt-get commandbelow. (The Raspberry Pi must have access to the internet.)apt-get updateStep 2Load the necessary packages, using the commands below:sudo apt-get install ssmtpsudo apt-get install mailutilssudo apt-get install mpackwww.sf-innovations.co.uk
  • 3. Step 3: Edit the SSMTP config file(You will need to be familiar with the nano editing package to do thefollowing.)At the command line, type “sudo nano /etc/ssmtp/ssmtp.conf” to edit thessmtp.conf file as follows:AuthUser=youruserid@gmail.comAuthPass=yourpasswordFromLineOverride=YESmailhub=smtp.gmail.com:587UseSTARTTLS=YESNote: You will need a gmail account to try this out.www.sf-innovations.co.uk
  • 4. Step 4: Send test e-mail from command lineTest that the e-mail can be sent by typing the following at the command line.echo "sample text" | mail -s "Subject" username@domain.xxxAn e-mail with the subject line “Subject” and content “sample text” will besent to the e-mail address username@domain.xxxThe next few steps are an example of how this could be done fromwithin a Python program.www.sf-innovations.co.uk
  • 5. Step 5: Create a bash file with e-mail command in.This is a file with extension .sh which can be used to produce an executablefile that can be called from within Python.Using the Leafpad editor create a file called email.sh with the following lines.#!/bin/bashecho "sample text" | mail -s "Subject" username@domain.comStep 6: Make the bash file executableThis saved bash file needs to be made executable by typing the following atthe command line.chmod +x email.shNow send a test email by typing the following at the command line../email.sh You should get an e-mail.www.sf-innovations.co.uk
  • 6. Step 7: Allow this file to be executable like any other command.Type in the following at the command line.Sudo cp email.sh /usr/local/bin/Step 8: Embed this into a Python scriptRemember to import the relevant library at the start.import osThen in the section of the program where you want to send an email use thefollowing commandos.system(„email‟)www.sf-innovations.co.uk
  • 7. SummaryHope this presentation has been useful in learning how to send an e-mailfrom the Raspberry Pi under program control. For example this e-mailcould be sent from a Python script on a trigger event such as atemperature drop or intruder alarm.Thanks to the following blogs for providing useful information.http://rpi.tnet.com/project/faqs/smtphttp://iqjar.com/jar/sending-emails-from-the-raspberry-pi/Keep an eye on our website www.sf-innovations.co.uk for any updates tothis presentation, new Custard Pi layers or new presentations.www.sf-innovations.co.uk

×