-
Notifications
You must be signed in to change notification settings - Fork 7
/
use_mailer.py
51 lines (42 loc) · 1.6 KB
/
use_mailer.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
#coding: UTF8
"""
Design Patterns in Python
listing 1 for Chapter 3
"""
from mailer import Mailer
from mailer import Message
import urllib
msg1 = Message(From="[email protected]",
To=["[email protected]", "[email protected]"],
charset="utf-8")
msg1.Subject = "日本語のHTMLメール"
msg1.Html = """Hello, <b>日本語</b>"""
mailer = Mailer('smtp01.odn.ne.jp')
msg2 = Message(Body="ナイスボディー!", attachments=["picture.png"])
msg2.From = "[email protected]"
msg2.To = "[email protected]"
msg2.Subject = "日本語の添付ファイルメール"
msg2.charset = "utf-8"
mailer.send([msg1, msg2])
msg = Message()
msg.From = "[email protected]"
msg.To = "[email protected]"
msg.Subject = "テキストメール"
msg.Body = "これは日本語のキストメールでございます。"
msg.charset = "utf-8"
mailer.send(msg)
msg3 = Message(From="[email protected]",
To=["[email protected]", "[email protected]"],
charset="utf-8")
msg3.Subject = "HTML with Attachment"
msg3.Html = """Hello, <b>日本語</b>"""
msg3.attach("picture.png")
mailer.send(msg3)
# now try specifying the MIME type
msg4 = Message(From="[email protected]",
To=["[email protected]", "[email protected]"],
charset="utf-8")
msg4.Subject = "HTML with Attachment (MIME type specified)"
msg4.Html = """Hello, please have a look at this image."""
msg4.attach("picture.png", mimetype="image/png")
mailer.send(msg4)