Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:02
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
#!/usr/bin/env python3
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.headerregistry import Address
# Create the base text message.
msg = MIMEMultipart('related')
msg['Subject'] = "Ayons asperges pour le déjeuner"
msg['From'] = Address("Pepé Le Pew", "")
msg['To'] = (Address("Penelope Pussycat", ""),
Address("Fabrette Pussycat", ""))
html = """\
<img src="cid:{0}" \>
<p>Cela ressemble à un excellent
<a href=">
</a> déjeuner.
<img src="cid:{1}" \>
msg.add_related(html, 'html')
with open("roasted-asparagus.jpg", 'rb') as img:
cid = msg.add_related(, 'image', 'jpeg')
with open("new-image.jpg", 'rb') as img:
cid = msg.add_related(, 'image', 'jpeg')
# Make a local copy of what we are going to send.
with open('outgoing.msg', 'wb') as f:
# Send the message via local SMTP server.
with smtplib.SMTP('localhost') as s:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment