Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Korakot Chaovavanich http://korakot.stumbleupon.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Sending html mail with embedded image

See detail in this recipe.
The code below show the key parts of embedding an image.
   1  
   2  # require the new email package
   3  from email.MIMEMultipart import MIMEMultipart
   4  from email.MIMEText import MIMEText
   5  from email.MIMEImage import MIMEImage
   6  
   7  ...
   8  ...
   9  msgRoot = MIMEMultipart('related')
  10  ...
  11  ...
  12  
  13  # Assumes the image is in current directory
  14  fp = open('test.jpg', 'rb')
  15  msgImage = MIMEImage(fp.read())
  16  fp.close()
  17  
  18  # Define the image's ID as referenced above
  19  msgImage.add_header('Content-ID', '<image1>')
  20  msgRoot.attach(msgImage)
  21  
  22  ...
  23  smtp.sendmail(strFrom, strTo, msgRoot.as_string())
  24  ...
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS