Hardware Reference
In-Depth Information
he URL or IP address of the e-mail SMTP server
Your username
Your password
If you do not have these, you can use a Gmail or Yahoo! account. You will be creating a
Python program called sendemail.py that will send a plain-text e-mail. he program
accepts two command-line parameters. A command-line parameter is a value that you pass to
the program. In this case you are passing the e-mail content as a parameter, as follows:
sudo python sendemail.py “Web cam motion detected”
sudo is a command telling the operating system to use super user rights when executing the
command. Python tells the operating system to run some Python script. sendemail.py is
the Python script you want to execute, and “Web cam motion detected” is the param-
eter you are passing into the sendemail.py program.
Create a ile called sendemail.py that contains the code in Listing 13-4. Go through each
line of code and ensure that you have illed in the details speciied in the code comments.
Listing 13-4 Send E-mail
#!/usr/bin/env python
“””
Home Automation: send e-mail
For the Raspberry Pi
“””
import sys
import smtplib
from email.mime.text import MIMEText
import time
def SendEmail(MessageText):
#enter the e-mail account username between the quotes
smtp_user = “”
#enter the e-mail account password between the quotes
smtp_pass = “”
#sys.argv[1] is the 1st parameter that is passed to
#this program and it contains the text for the body
Search WWH ::




Custom Search