forked from farmerx/mail
-
Notifications
You must be signed in to change notification settings - Fork 4
/
mail_test.go
40 lines (36 loc) · 1.13 KB
/
mail_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
package smtp
import (
"testing"
"github.com/cmarkh/SMTP/golang.org/x/net/smtp"
)
func Test_SendMail(t *testing.T) {
email := NewEMail(`{"port":25}`)
email.From = `[email protected]`
email.Host = `smtp.163.com`
email.Port = int(25) // [587 NTLM AUTH] [465,994]
email.Username = `Farmerx`
email.Secure = `` // SSL,TSL
email.Password = `************`
authType := `LOGIN`
switch authType {
case ``:
email.Auth = nil
case `LOGIN`:
email.Auth = LoginAuth(email.Username, email.Password)
case `CRAM-MD5`:
email.Auth = smtp.CRAMMD5Auth(email.Username, email.Password)
case `PLAIN`:
email.Auth = smtp.PlainAuth(email.Identity, email.Username, email.Password, email.Host)
case `NTLM`:
email.Auth = NTLMAuth(email.Host, email.Username, email.Password, NTLMVersion1)
default:
email.Auth = smtp.PlainAuth(email.Identity, email.Username, email.Password, email.Host)
}
email.To = []string{`[email protected]`}
email.Subject = `send mail success`
email.Text = "尊敬的用户:\r\n 您好,附件中是您订阅的报表,请注意查收。"
//email.AttachFile(reportFile)
if err := email.Send(); err != nil {
t.Error(err)
}
}