SlideShare a Scribd company logo
1 of 7
RASPBERRY PI
Sending an e-mail from a Python script
www.sf-innovations.co.uk
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.
Step 1
Make sure that all everything is up to date by using the apt-get command
below. (The Raspberry Pi must have access to the internet.)
apt-get update
Step 2
Load the necessary packages, using the commands below:
sudo apt-get install ssmtp
sudo apt-get install mailutils
sudo apt-get install mpack
www.sf-innovations.co.uk
Step 3: Edit the SSMTP config file
(You will need to be familiar with the nano editing package to do the
following.)
At the command line, type “sudo nano /etc/ssmtp/ssmtp.conf” to edit the
ssmtp.conf file as follows:
AuthUser=youruserid@gmail.com
AuthPass=yourpassword
FromLineOverride=YES
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
Note: You will need a gmail account to try this out.
www.sf-innovations.co.uk
Step 4: Send test e-mail from command line
Test that the e-mail can be sent by typing the following at the command line.
echo "sample text" | mail -s "Subject" username@domain.xxx
An e-mail with the subject line “Subject” and content “sample text” will be
sent to the e-mail address username@domain.xxx
The next few steps are an example of how this could be done from
within a Python program.
www.sf-innovations.co.uk
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 executable
file that can be called from within Python.
Using the Leafpad editor create a file called email.sh with the following lines.
#!/bin/bash
echo "sample text" | mail -s "Subject" username@domain.com
Step 6: Make the bash file executable
This saved bash file needs to be made executable by typing the following at
the command line.
chmod +x email.sh
Now 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
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 script
Remember to import the relevant library at the start.
import os
Then in the section of the program where you want to send an email use the
following command
os.system(„email‟)
www.sf-innovations.co.uk
Summary
Hope this presentation has been useful in learning how to send an e-mail
from the Raspberry Pi under program control. For example this e-mail
could be sent from a Python script on a trigger event such as a
temperature drop or intruder alarm.
Thanks to the following blogs for providing useful information.
http://rpi.tnet.com/project/faqs/smtp
http://iqjar.com/jar/sending-emails-from-the-raspberry-pi/
Keep an eye on our website www.sf-innovations.co.uk for any updates to
this presentation, new Custard Pi layers or new presentations.
www.sf-innovations.co.uk

More Related Content

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Recently uploaded (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Raspberry Pi - Sending an E-mail

  • 1. RASPBERRY PI Sending an e-mail from a Python script www.sf-innovations.co.uk
  • 2. 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. Step 1 Make sure that all everything is up to date by using the apt-get command below. (The Raspberry Pi must have access to the internet.) apt-get update Step 2 Load the necessary packages, using the commands below: sudo apt-get install ssmtp sudo apt-get install mailutils sudo apt-get install mpack www.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 the following.) At the command line, type “sudo nano /etc/ssmtp/ssmtp.conf” to edit the ssmtp.conf file as follows: AuthUser=youruserid@gmail.com AuthPass=yourpassword FromLineOverride=YES mailhub=smtp.gmail.com:587 UseSTARTTLS=YES Note: You will need a gmail account to try this out. www.sf-innovations.co.uk
  • 4. Step 4: Send test e-mail from command line Test that the e-mail can be sent by typing the following at the command line. echo "sample text" | mail -s "Subject" username@domain.xxx An e-mail with the subject line “Subject” and content “sample text” will be sent to the e-mail address username@domain.xxx The next few steps are an example of how this could be done from within 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 executable file that can be called from within Python. Using the Leafpad editor create a file called email.sh with the following lines. #!/bin/bash echo "sample text" | mail -s "Subject" username@domain.com Step 6: Make the bash file executable This saved bash file needs to be made executable by typing the following at the command line. chmod +x email.sh Now 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 script Remember to import the relevant library at the start. import os Then in the section of the program where you want to send an email use the following command os.system(„email‟) www.sf-innovations.co.uk
  • 7. Summary Hope this presentation has been useful in learning how to send an e-mail from the Raspberry Pi under program control. For example this e-mail could be sent from a Python script on a trigger event such as a temperature drop or intruder alarm. Thanks to the following blogs for providing useful information. http://rpi.tnet.com/project/faqs/smtp http://iqjar.com/jar/sending-emails-from-the-raspberry-pi/ Keep an eye on our website www.sf-innovations.co.uk for any updates to this presentation, new Custard Pi layers or new presentations. www.sf-innovations.co.uk