forked from AstarLight/verification-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmail_test.go
More file actions
38 lines (31 loc) · 791 Bytes
/
mail_test.go
File metadata and controls
38 lines (31 loc) · 791 Bytes
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
package main
import (
"testing"
"fmt"
)
func TestSendAndVerify(t *testing.T) {
mailUser := "lijunshi_mhxy7@163.com"
mailPass := "" // 授权码
mailTo := "lijunshi2015@163.com"
codeLen := 4
codeTTL := 5*60
from := "login" // 业务场景标记
code := GenRandomCode(codeLen)
subjectText := "登录验证码" // 邮件主题
bodyText := fmt.Sprintf("您的验证码是:%s, 有效期为5分钟", code) // 邮件正文
options := &MailOptions{
MailUser: mailUser,
MailPass: mailPass,
MailTo: mailTo,
Subject: subjectText,
Body: bodyText,
}
err := SendMailCode(options, code, from, codeTTL)
if err != nil {
t.Error("SendMailCode error", err)
}
err = ValidateMailCode(mailTo, code, from)
if err != nil {
t.Error("ValidateMailCode error", err)
}
}