Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # send e-mail with python
- import smtplib
- from email.mime.multipart import MIMEMultipart
- from email.mime.text import MIMEText
- from email.mime.image import MIMEImage
- msg = MIMEMultipart()
- msg['Subject'] = 'RPi Python test'
- msg['From'] = 'raspberrypitm@gmail.com'
- msg['To'] = 'kennyjoris97@gmail.com'
- msg.preamble ='This is a multifart message in MIME format.'
- message = """This is a test of using Python on Raspberry Pi
- to send an email."""
- msg.attach(MIMEText(message))
- filename = 'RaspberryPI.jpg'
- with open(filename, 'rb') as f:
- img = MIMEImage(f.read())
- img.add_header('Content-Disposition', 'attachment', filename=filename)
- msg.attach(img)
- username = 'raspberrypitm@gmail.com'
- password = 'thomasmore'
- server = smtplib.SMTP('smtp.gmail.com:587')
- server.starttls()
- server.login(username,password)
- server.sendmail(msg['From'], msg['To'], msg.as_string())
- server.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement