Last active
August 29, 2015 14:02
-
-
Save maxking/b3ed4f54674e5f480275 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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", "pepe@example.com") | |
msg['To'] = (Address("Penelope Pussycat", "penelope@example.com"), | |
Address("Fabrette Pussycat", "fabrette@example.com")) | |
html = """\ | |
<html> | |
<head></head> | |
<body> | |
<p>Salut!<\p> | |
<img src="cid:{0}" \> | |
<p>Cela ressemble à un excellent | |
<a href="http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718> | |
recipie | |
</a> déjeuner. | |
</p> | |
<img src="cid:{1}" \> | |
</body> | |
</html> | |
""" | |
msg.add_related(html, 'html') | |
with open("roasted-asparagus.jpg", 'rb') as img: | |
cid = msg.add_related(img.read(), 'image', 'jpeg') | |
with open("new-image.jpg", 'rb') as img: | |
cid = msg.add_related(img.read(), 'image', 'jpeg') | |
# Make a local copy of what we are going to send. | |
with open('outgoing.msg', 'wb') as f: | |
f.write(bytes(msg)) | |
# Send the message via local SMTP server. | |
with smtplib.SMTP('localhost') as s: | |
s.send_message(msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment