Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learning Beaglebone Python Programming

You're reading from  Learning Beaglebone Python Programming

Product type Book
Published in Jul 2015
Publisher
ISBN-13 9781784399702
Pages 196 pages
Edition 1st Edition
Languages

SMTP


We've looked at various forms of displays that you can attach to your BeagleBone, but those are only useful when you're looking at it. If your BeagleBone is not accessible, for instance, it's monitoring something at your home while you're out, you might still need a way for it to send you information. One simple way to achieve this is to use Simple Mail Transfer Protocol (SMTP) to send e-mails from your BeagleBone. Save this code to a new file called email_sender.py by filling in your account's SMTP details:

import smtplib
from email.mime.text import MIMEText

SMTP_host = 'smtp.gmail.com'
SMTP_email = 'username@gmail.com'
SMTP_pass = 'password'

def send_email(to, subject, body):
  msg = MIMEText(body)
  msg['Subject'] = subject
  msg['From'] = SMTP_email
  msg['To'] = to
  server = smtplib.SMTP_SSL(SMTP_host)
  server.login(SMTP_email, SMTP_pass)
  server.sendmail(SMTP_email, to, msg.as_string())

Note

Just like with IMAP, to retrieve e-mails, SMTP is a standard protocol and is used by...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}