-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
56 lines (45 loc) · 1.54 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import smtplib
import time
# Here are the email package modules we'll need.
from email.message import EmailMessage
from email.utils import make_msgid
# Create the container email message.
msg = EmailMessage()
msg['Subject'] = 'Hello SMTP Preview' + time.ctime()
# me == the sender's email address
# family = the list of all recipients' email addresses
msg['From'] = '[email protected]'
msg['To'] = ', '.join(['[email protected]'])
msg.preamble = 'SMTP Preview is a tool for testing and inspecting email sending\n'
msg.set_content("""\
Salut!
Cela ressemble à un excellent recipie[1] déjeuner.
[1] http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718
--Pepé
""")
asparagus_cid = make_msgid()
msg.add_alternative("""\
<html>
<head></head>
<body>
<p>Salut!</p>
<p>Cela ressemble à un excellent
<a href="http://www.yummly.com/recipe/Roasted-Asparagus-Epicurious-203718">
recipie
</a> déjeuner.
</p>
<img src="cid:{asparagus_cid}" />
</body>
</html>
""".format(asparagus_cid=asparagus_cid[1:-1]), subtype='html')
with open("./ui/src/assets/logo.png", 'rb') as img:
msg.get_payload()[1].add_related(img.read(), 'image', 'png',
cid=asparagus_cid)
img_data = open('./ui/src/assets/logo.png', 'rb').read()
msg.add_attachment(img_data, maintype='image',
subtype='png', filename='logo.png')
conn = smtplib.SMTP('localhost', port=9025)
# Mock login
conn.login('[email protected]', 'smtppreview')
r = conn.send_message(msg)
print('send ok, result:', r)