Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering

Sending Mail from Beaglebone Black (Part 9/15)

By Ashish Vara

This tutorial explains how to send mail from Beaglebone black using SMTP protocol. SMTP stands for Simple Mail transfer protocol. The  main objective of this tutorial is to obtain mail notification upon certain activity. BBB will send the mail with predefined message to registered email id when some activity  takes place. Network (Internet) connectivity is required for this tutorial. You can also attach some file with mail. Program is written in python script with SMTP library and adafruit GPIO library.

Required Tools:

  • Beaglebone Black
  • Push button
  • LED
  • 1 kΩ Resistor
  • 330 Ω resistor

Breadboard

  • Female to Female connectors

Setup of Software environment

Install the latest python version in BBB as explained in tutorial How to make first python program with Beaglebone Black. Adafruit python –GPIO library is already installed but you can also manually install the library named adafruit_BBIO. SMTP library is installed with python but check once before making application.

Working

In this tutorial, simple alert notification is sent to specific mail ID. Before running application, you need to establish internet connection with Beaglebone black. You can choose either Ethernet connection or WI-FI device. This tutorial uses Ethernet cable to provide internet connection. When switch is pressed, mail is sent to specific email ID with predefined message. When script is running, program enters into a continuous loop. Led turns ON when switch is pressed and turns OFF after the mail has been sent from BBB.

When mail is sent following message is displayed on command prompt:

Mail has been sent

Press the ctrl+C  to stop the execution of program form SSH command terminal.

Open receiver’s mail box and check  if the message is received or not.

Screenshot of Mail Sent from Beaglebone Black

Fig. 1: Screenshot of Mail Sent from Beaglebone Black

Description

Let’s first prepare the circuit connection. Take a breadboard and provide VCC and ground from BBB to breadboard line. Connect Supply 3.3 V from pin number 3rd of header P9 and ground from pin number 2nd of header P8. Connect the negative terminal of  LED with ground and the positive one with 330 Ohm resistor.. Connect another end of resistor with pin number 10th of header P8.  Push button has two terminals. Any one of them connects with ground. Provide the VCC 3.3 V through 1k ohm resistor to another terminal of push button. Connect the common end of resistor and push button with pin number 11th of header P8. Provide the supply to Beaglebone black by connecting it with PC through USB cable. Now your circuit is prepared.

Open the command terminal and access Beaglebone black through SSH as explained in getting started with Beaglebone black. Create a new file using touch command with .py extension (i.e. led.py). Open the file with any text editor (i.e. nano, vim etc.) and write a code in python language.

SMTP Setup

You can send email using SMTP across the internet which handles the service over TCP/IP network. Two things are required to establish connection with mail server:

  1. Mail server address
  2. Port number

SMTP library has inbuilt function to setup the configuration for sending mail. Set the mail address and port number as following function:

smtplib.SMTP (“smtp.gmail.com”, 587)

Here I have used Gmail server with appropriate port number for sending mail. First argument is mail server address and second argument is port number.

After connecting with mail server, BBB (act as a client) indentifies and establishes secure connection by following functions respectively.

ehlo( ) – Enable and identify connection with mail server

starttls( ) – provide secure connection to transfer data

Configure sender email ID, password, receiver email ID and message which you want to send to the receiver.

To = “Receiver’s mail ID”

            From = “Sender’s mail ID”

            Password = “Sender’s mail ID password”

            message = “Alert!!! Button is pressed”

You can write message as per your wish.

Login in to the server with specific ID and password. Send the message on receiver’s email ID and close the connection.

GPIO configuration

I have already explained GPIO setup in Switch interfacing with Beaglebone black.

Run the script from terminal:

Enter the following command with file name from command prompt:

            python filename.py

i.e. python sendmail.py

Project Source Code

###


import smtplib
import time
 
import Adafruit_BBIO.GPIO as GPIO
 
LED = "P8_10"
BUTTON = "P8_11"
 
 
GPIO.setup ( LED , GPIO.OUT)
GPIO.setup ( BUTTON , GPIO.IN) 
 
GPIO.output ( LED , GPIO.LOW)
 
while True:
Button_State = GPIO.input (BUTTON)
if Button_State  == 0:
GPIO.output ( LED , GPIO.HIGH)
time.sleep (1)
server = smtplib.SMTP("smtp.gmail.com" , 587)
server.ehlo()
server.starttls()
server.ehlo()
To = "[email protected]"
From = "[email protected]"
Password = "Password"
message = "Alert!!! Button is pressed"
 
server.login( From , Password)
server.sendmail( From , To, message)
server.quit()
print("Mail has been sent")
 
GPIO.output ( LED , GPIO.LOW)

###

 


Circuit Diagrams

Circuit-Diagram-Beaglebone-Black

Project Video


Filed Under: Electronic Projects

 

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Adjustable 0 to 30V 2A DC Power Supply Circuit (Part 1/13)
  • Adjustable +/- 1.25V to +/-22V 1A Power Supply Circuit (Part 2/13)
  • Adjustable 0 to 15V 1A Mini Power Supply (Part 3/13)
  • Constant 12V Power Supply for LED Circuits (Part 4/13)
  • Constant +/-9V DC Symmetrical Power Supply Circuit (Part 5/13)
  • Making a Circuit Breaker (Part 6/13)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

“ee

“ee

“ee

“ee

“ee

“ee

Recent Articles

  • STMicroelectronics and MACOM announce successful RF GaN-on-Si prototypes
  • Infineon expands its CoolSiC portfolio
  • STMicroelectronics and AWS collaborate for secure IoT connections
  • Pet feeding system using WhatsApp (protocol bridging with MQTT)
  • STMicroelectronics launches new MDmesh MOSFETs

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd ldr led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics Research robot samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • P-Channel MOSFET always on
  • Space Vector PWM Help Needed
  • Power Supply Design ideas Please for Mains LED Strip
  • Unable to launch virtuoso: libvisadev.so error
  • Help with Verilog replicate operator

RSS Electro-Tech-Online.com Discussions

  • XOR Gate Circuit From Diodes
  • 3.3V microcontroller vs 5V relay
  • How to get lots of PCBs made cheap?
  • What is this part on my solar controller
  • High component count for long delay circuit (inrush resistor switch out)
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering