SHARE
TWEET

Untitled

a guest Dec 6th, 2016 143 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # send e-mail with python
  2. import smtplib
  3. from email.mime.multipart import MIMEMultipart
  4. from email.mime.image import MIMEImage
  5. from email.mime.text import MIMEText
  6.  
  7.  
  8. msg = MIMEMultipart()
  9. msg['Subject'] = 'mail with attachment'
  10. msg['From'] = 'arne.van.bael@gmail.com'
  11. msg['To'] = 'quintenscheppermans@gmail.com'
  12. msg.preamble = 'this is a multipart message in MIME format'
  13.  
  14. # create the email content
  15. message = """This is a test of using Python on Raspberry Pi
  16. to send an email."""
  17.  
  18. msg.attach(MIMEText(message))
  19.  
  20. #attach a pdf file
  21. filename = 'bijlage.jpg'
  22. with open(filename, 'rb') as f:
  23.     img = MIMEImage(f.read())
  24. img.add_header('Content-Disposition','attachment',filename=filename)
  25.  
  26. msg.attach(img)
  27.  
  28. # send the email via Gmail server
  29. username = 'arne.van.bael@gmail.com'
  30. password = ''
  31. server = smtplib.SMTP('smtp.gmail.com:587') # Gmail rewriting port 25 to port 587
  32. server.starttls()                           # Support SMPT AUTH
  33. server.login(username,password)
  34. server.sendmail(msg['From'], msg['To'], msg.as_string())
  35. server.quit()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top