Hardware Reference
In-Depth Information
Listing 13-7 is the code for emailphoto.py that will attach a photograph to the e-mail. I
have created a function called emailphoto because it is used in other programs within this
chapter.
Listing 13-7 Send E-mail with a Photo Attachment
#!/usr/bin/env python
“””
Home Automation: sends an e-mail with a photograph attachment
For the Raspberry Pi
“””
import sys
import smtplib
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
def emailphoto(msgtext, afilename):
#enter the e-mail account username between the quotes
smtp_user = “”
#enter the e-mail account password between the quotes
smtp_pass = “”
msg = MIMEMultipart()
#enter the target e-mail address between the quotes
msg['To'] = “”
#enter the e-mail account username between the quotes
msg['From'] = “”
#enter the message subject between the quotes
msg['Subject'] = “”
#That is what you see if don't have an e-mail reader:
msg.preamble = 'Multipart message.\n'
#sys.argv[1] is the 1st parameter that is passed to this
#and it contains the text for the body of the e-mail
part = MIMEText(msgtext)
msg.attach(part)
continued
Search WWH ::




Custom Search