Notes:
Lesson 4.2: Email application
Email is transferred across the internet using something called SMTP – Simple Mail Transfer Protocol. SMTP uses port 25. Don’t worry; you don’t need to understand how SMTP works to be able to send an email. There is a Python module that does all the hard work for you.
Use the Python script below to send a single email.
email-example.py:
import smtplib from email.mime.text import MIMEText # create the email message = """This is a test of using Python on Raspberry Pi to send an email. Have fun!""" msg = MIMEText(message) msg[ 'Subject' ] = 'RPi Python test' msg[ 'From' ] = 'My RPi
You can modify the program to send email attachments as well as simple text. The example on the next page sends an image (such as a JPG file) as an attachment to the message.
Human-computer interfacing
116
Made with FlippingBook flipbook maker