-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailer_test.go
66 lines (54 loc) · 1.13 KB
/
mailer_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
package mailer
import (
"testing"
)
// Provide a valid smtp config
var (
host = "mail.xxx.com"
user = "send@xxx.com"
pass = "xxx"
recipent = "rcpt1@xxx.com"
recipent2 = "rcpt2@xxx.com"
)
func TestSMTP(t *testing.T) {
config := Config{
Host: host,
Port: 25,
User: user,
Pass: pass,
}
mailer := NewMailer(config, false)
mail := NewMail()
mail.FromName = "Go Mailer"
mail.From = user
mail.SetTo(recipent)
mail.Subject = "Go SMTP Test"
mail.Body = "This is a test e-mail from Go Mailer via SMTP"
if err := mailer.Send(mail); err != nil {
t.Errorf("Send error: %s", err)
}
}
func TestSMTPSSL(t *testing.T) {
config := Config{
Host: host,
Port: 465,
User: user,
Pass: pass,
}
mailer := NewMailer(config, true)
mail := NewMail()
mail.FromName = "Go Mailer"
mail.From = user
// multiple recipents
mail.SetTo(recipent)
mail.SetTo(recipent2)
mail.Subject = "Go SMTP SSL Test"
// the rich message body
mail.Body = `
<h2>Hello from Go Mailer</h2>
<p>This is a test e-mail from Go Mailer via SMTP SSL</p>
`
if err := mailer.Send(mail); err != nil {
t.Errorf("Send error: %s", err)
}
}