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.image import MIMEImage
- from email.mime.text import MIMEText
- msg = MIMEMultipart()
- msg['Subject'] = 'mail with attachment'
- msg['From'] = 'arne.van.bael@gmail.com'
- msg['To'] = 'quintenscheppermans@gmail.com'
- msg.preamble = 'this is a multipart message in MIME format'
- # create the email content
- message = """This is a test of using Python on Raspberry Pi
- to send an email."""
- msg.attach(MIMEText(message))
- #attach a pdf file
- filename = 'bijlage.jpg'
- with open(filename, 'rb') as f:
- img = MIMEImage(f.read())
- img.add_header('Content-Disposition','attachment',filename=filename)
- msg.attach(img)
- # send the email via Gmail server
- username = 'arne.van.bael@gmail.com'
- password = ''
- server = smtplib.SMTP('smtp.gmail.com:587') # Gmail rewriting port 25 to port 587
- server.starttls() # Support SMPT AUTH
- 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