-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmsg_test.go
157 lines (129 loc) · 3.99 KB
/
msg_test.go
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package mailx
import (
"io"
"net/mail"
"strings"
"testing"
"time"
)
func TestMessage1(t *testing.T) {
m := NewMessage()
m.SetSingleRecvAddr(true)
m.SetSender("[email protected]")
m.SetTo("[email protected]")
m.AddTo("[email protected]")
m.SetCc("[email protected]")
m.AddCc("[email protected]")
m.SetBcc("[email protected]")
m.AddBcc("[email protected]")
m.SetSubject("This is a subject of email.")
_, err := m.WriteTo(io.Discard)
if err != nil {
t.Fatalf("write message, err: %s", err.Error())
}
}
func TestMessage2(t *testing.T) {
m := NewMessage()
m.SetFrom(&mail.Address{Name: "alex", Address: "[email protected]"})
m.SetRcptTo(&mail.Address{Name: "aaa-1", Address: "[email protected]"})
m.AddRcptTo(&mail.Address{Name: "aaa-2", Address: "[email protected]"})
m.SetRcptCc(&mail.Address{Name: "bbb-1", Address: "[email protected]"})
m.AddRcptCc(&mail.Address{Name: "bbb-2", Address: "[email protected]"})
m.SetRcptBcc(&mail.Address{Name: "ccc-1", Address: "[email protected]"})
m.AddRcptBcc(&mail.Address{Name: "ccc-2", Address: "[email protected]"})
m.SetSubject("This is a subject of email.")
_, err := m.WriteTo(io.Discard)
if err != nil {
t.Fatalf("write message, err: %s", err.Error())
}
}
func TestMessage3(t *testing.T) {
m := NewMessage()
m.SetSender("[email protected]")
m.SetTo("[email protected]")
m.SetSubject("This is a subject of email.")
m.SetPlainBody("This is a text/plain body.This is a text/plain body.")
m.AddPlainBody("This is a text/plain body.This is a text/plain body.")
_, err := m.WriteTo(io.Discard)
if err != nil {
t.Fatalf("write message, err: %s", err.Error())
}
}
func TestMessage4(t *testing.T) {
m := NewMessage()
m.SetSender("[email protected]")
m.SetTo("[email protected]")
m.SetSubject("This is a subject of email.")
m.SetHtmlBody("<p>This is a text/html body.This is a text/html body.</p>")
m.AddHtmlBody("<p>This is a text/html body.This is a text/html body.</p>")
_, err := m.WriteTo(io.Discard)
if err != nil {
t.Fatalf("write message, err: %s", err.Error())
}
}
func TestMessage5(t *testing.T) {
m := NewMessage()
m.SetSender("[email protected]")
m.SetTo("[email protected]")
m.SetSubject("This is a subject of email.")
m.SetCopierBody("text/plain", func(w io.Writer) (int, error) {
body := strings.Repeat("This is a text/plain body.", 4)
return io.WriteString(w, body)
})
m.AddCopierBody("text/html", func(w io.Writer) (int, error) {
body := strings.Repeat("<p>This is a text/html body.</p>", 4)
return io.WriteString(w, body)
})
_, err := m.WriteTo(io.Discard)
if err != nil {
t.Fatalf("write message, err: %s", err.Error())
}
}
func TestMessage6(t *testing.T) {
m := NewMessage()
m.SetSender("[email protected]")
m.SetTo("[email protected]")
m.SetSubject("This is a subject of email.")
m.SetHtmlBody(`This is a text/html body. <img src="cid:CID0"/>`)
m.Embed("CID0", func(w io.Writer) (int, error) {
return io.WriteString(w, "this is a embedded attachment.")
})
m.Attach("attach.txt", func(w io.Writer) (int, error) {
return io.WriteString(w, "this is a txt attachment.")
})
_, err := m.WriteTo(io.Discard)
if err != nil {
t.Fatalf("write message, err: %s", err.Error())
}
}
func TestMessage7(t *testing.T) {
m := NewMessage()
m.SetSender("[email protected]")
m.SetTo("[email protected]")
m.SetUserAgent("ua - test mailx")
m.SetDate(time.Now().Format(time.RFC1123Z))
m.AddHeader("extra", "EXTRA HEADER")
m.SetSubject("This is a subject of email.")
_, err := m.WriteTo(io.Discard)
if err != nil {
t.Fatalf("write message, err: %s", err.Error())
}
}
func TestErrMessage1(t *testing.T) {
m := NewMessage()
m.SetSender("[email protected]")
m.SetSubject("This is a subject of email.")
_, err := m.WriteTo(io.Discard)
if err != nil {
t.Logf("write message, err: %s", err.Error())
}
}
func TestErrMessage2(t *testing.T) {
m := NewMessage()
m.SetSender("[email protected]")
m.SetTo("[email protected]")
_, err := m.WriteTo(io.Discard)
if err != nil {
t.Logf("write message, err: %s", err.Error())
}
}