Over a million developers have joined DZone.

Sending Html Mail With Embedded Image

DZone's Guide to

Sending Html Mail With Embedded Image

· ·
Free Resource
See detail in this recipe.
The code below show the key parts of embedding an image.

# require the new email package
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage

msgRoot = MIMEMultipart('related')

# Assumes the image is in current directory
fp = open('test.jpg', 'rb')
msgImage = MIMEImage(fp.read())

# Define the image's ID as referenced above
msgImage.add_header('Content-ID', '

smtp.sendmail(strFrom, strTo, msgRoot.as_string())


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}