-
Notifications
You must be signed in to change notification settings - Fork 54
/
send-invite-email.go
71 lines (62 loc) · 1.81 KB
/
send-invite-email.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
package main
import (
"github.com/QLeelulu/goku"
"github.com/QLeelulu/ohlala/golink"
"github.com/QLeelulu/ohlala/golink/models"
"github.com/QLeelulu/ohlala/golink/utils"
//"strings"
"fmt"
"time"
)
func main() {
for {
fmt.Println("entry")
oneSuccess := false
emails, err := models.GetEmailForSend()
if err != nil {
goku.Logger().Errorln(err.Error())
} else {
for _, email := range emails {
err := sendMail(email)
if err != nil {
fmt.Println(err)
email.SendSuccess = false
} else {
fmt.Println("send", email)
email.SendSuccess = true
oneSuccess = true
}
}
//更新状态
if oneSuccess == true && len(emails) > 0 {
models.UpdateInviteEmailStatus(emails)
continue
}
}
fmt.Println("sleep")
time.Sleep(300 * time.Second) // 每5分钟
}
}
func sendMail(email *models.EmailInvite) error {
user := "[email protected]"
password := "xxx"
host := "smtp.163.com:25"
to := email.ToEmail
subject := fmt.Sprintf("%s 邀请你加入觅链", email.UserName)
body := fmt.Sprintf(`
<html>
<body>
%s 邀请你加入觅链
<br/>
觅链(<a href="http://%s">%s</a>)是一个由大家共建的XXXXXXX社区,简介XXXXXXXXX。
<br/>
请点击以下链接完成注册:
<a href="http://%s/user/reg?key=%s">http://%s/user/reg?key=%s</a>
<br/>
© 觅链 2013
</body>
</html>
`, email.UserName, golink.Host_Name, golink.Host_Name, golink.Host_Name, email.Guid, golink.Host_Name, email.Guid)
err := utils.SendMail(user, password, host, to, subject, body, "html")
return err
}