Repository navigation
Expand file tree
/
Copy pathgsmtp_test.go
More file actions
78 lines (64 loc) · 1.96 KB
/
Copy pathgsmtp_test.go
File metadata and controls
78 lines (64 loc) · 1.96 KB
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
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://github.com/gogf/gf.
package gsmtp_test
import (
"strings"
"testing"
"github.com/gogf/gf/net/gsmtp"
)
func TestAddress(t *testing.T) {
errMessage := "address is either empty or incorrect"
errValues := []string{
"",
":",
":25",
"localhost:",
"local.host:25:28",
}
for _, errValue := range errValues {
smtpConnection := gsmtp.New(errValue, "smtpUser@smtp.exmail.qq.com", "smtpPassword")
res := smtpConnection.SendMail("sender@local.host", "recipient1@domain.com;recipientN@anotherDomain.cn", "This is subject", "Hi! <br><br> This is body")
if !strings.Contains(res.Error(), errMessage) {
t.Errorf("Test failed on Address: %s", errValue)
}
}
}
func TestFrom(t *testing.T) {
errMessage := "from is invalid"
errValues := []string{
"",
"qwerty",
// "qwe@rty@com",
// "@rty",
// "qwe@",
}
for _, errValue := range errValues {
smtpConnection := gsmtp.New("smtp.exmail.qq.com", "smtpUser@smtp.exmail.qq.com", "smtpPassword")
res := smtpConnection.SendMail(errValue, "recipient1@domain.com;recipientN@anotherDomain.cn", "This is subject", "Hi! <br><br> This is body")
if !strings.Contains(res.Error(), errMessage) {
t.Errorf("Test failed on From: %s", errValue)
}
}
}
func TestTos(t *testing.T) {
errMessage := "tos if invalid"
errValues := []string{
"",
"qwerty",
"qwe;rty",
"qwe;rty;com",
// "qwe@rty@com",
// "@rty",
// "qwe@",
}
for _, errValue := range errValues {
smtpConnection := gsmtp.New("smtp.exmail.qq.com", "smtpUser@smtp.exmail.qq.com", "smtpPassword")
res := smtpConnection.SendMail("from@domain.com", errValue, "This is subject", "Hi! <br><br> This is body")
if !strings.Contains(res.Error(), errMessage) {
t.Errorf("Test failed on Tos: %s", errValue)
}
}
}