Hardware Reference
In-Depth Information
Listing 13-6 continued
s = smtplib.SMTP_SSL(“”, 465)
s.login(smtp_user,smtp_pass)
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.quit()
def main():
SendEmail (sys.argv[1])
if __name__ == “__main__”:
main()
Sending E-mail Using a Gmail or Yahoo! Account
If you have a Gmail or Yahoo! account, you use your e-mail address as the e-mail account and
the e-mail password as the e-mail account password. Gmail uses SSL, so edit the SSL encryp-
tion code (in Listing 13-6) with the following SMTP server details:
smtp.gmail.com
Yahoo! uses TLS, so edit the TLS encryption code (in Listing 13-5) with the following as the
SMTP server details:
smtp.mail.yahoo.com
How to Attach a File to an E-mail
In the section “Project 2: How to Monitor Your Home with a Webcam”, a command was
introduced that enabled you to send a photograph attachment when the webcam detected
motion. he code in Listing 13-7 will allow you to do it. You will build on the sendemail.
py program you created earlier (in Listing 13-4) by adding a new parameter to pass the ile-
name of the photo you want to attach to the e-mail. Remember to update this program with
the code depending on the type of encryption you require as explained earlier. In this exam-
ple I've assumed SSL encryption. he emailphoto.py program accepts two parameters: the
irst for the message text and the second for the ilename of the photo you want to send. For
example, you will run this program using the following command:
sudo python sendemail.py 'Webcam motion detected', ;
'/home/photo.jpg'
Search WWH ::




Custom Search