blob: df7ca6f3faa332cbf28f1bcd5e82870477300bae [file] [log] [blame]
#!/usr/bin/env python3
import smtplib
from email.message import EmailMessage
from email.headerregistry import Address
from email.utils import make_msgid
# Create the base text message.
msg = EmailMessage()
msg['Subject'] = "Ayons asperges pour le déjeuner"
msg['From'] = Address("Pepé Le Pew", "pepe", "")
msg['To'] = (Address("Penelope Pussycat", "penelope", ""),
Address("Fabrette Pussycat", "fabrette", ""))
Cela ressemble à un excellent recipie[1] déjeuner.
# Add the html version. This converts the message into a multipart/alternative
# container, with the original text message as the first part and the new html
# message as the second part.
asparagus_cid = make_msgid()
<p>Cela ressemble à un excellent
<a href="">
</a> déjeuner.
<img src="cid:{asparagus_cid}" />
""".format(asparagus_cid=asparagus_cid[1:-1]), subtype='html')
# note that we needed to peel the <> off the msgid for use in the html.
# Now add the related image to the html part.
with open("roasted-asparagus.jpg", 'rb') as img:
msg.get_payload()[1].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: