@@ -48,6 +48,31 @@ Content-Type: text/html;charset=UTF-8
48
48
return nil
49
49
}
50
50
51
+ // sendMailBy163 通过163账号发送电子邮件
52
+ func (self EmailLogic ) sendMailBy163 (subject , content string , tos []string ) error {
53
+ emailConfig , err := config .ConfigFile .GetSection ("email.163" )
54
+ if err != nil {
55
+ return self .SendMail (subject , content , tos )
56
+ }
57
+ fromEmail := config .ConfigFile .MustValue ("email" , "from_email" )
58
+ message := `From: Go语言中文网 | Golang中文社区 | Go语言学习园地<` + fromEmail + `>
59
+ To: ` + strings .Join (tos , "," ) + `
60
+ Subject: ` + subject + `
61
+ Content-Type: text/html;charset=UTF-8
62
+
63
+ ` + content
64
+
65
+ smtpAddr := emailConfig ["smtp_host" ] + ":" + emailConfig ["smtp_port" ]
66
+ auth := smtp .PlainAuth ("" , emailConfig ["smtp_username" ], emailConfig ["smtp_password" ], emailConfig ["smtp_host" ])
67
+ err = smtp .SendMail (smtpAddr , auth , emailConfig ["smtp_username" ], tos , []byte (message ))
68
+ if err != nil {
69
+ logger .Errorln ("Send Mail to" , strings .Join (tos , "," ), "error:" , err )
70
+ return err
71
+ }
72
+ logger .Infoln ("Send Mail to" , strings .Join (tos , "," ), "Successfully" )
73
+ return nil
74
+ }
75
+
51
76
// 保存uuid和email的对应关系(TODO:重启如何处理)
52
77
var regActivateCodeMap = map [string ]string {}
53
78
@@ -177,7 +202,11 @@ func (self EmailLogic) EmailNotice() {
177
202
continue
178
203
}
179
204
180
- self .SendMail ("每周精选" , content , []string {user .Email })
205
+ if strings .HasSuffix (user .Email , "@163.com" ) {
206
+ self .sendMailBy163 ("每周精选" , content , []string {user .Email })
207
+ } else {
208
+ self .SendMail ("每周精选" , content , []string {user .Email })
209
+ }
181
210
182
211
// 控制发信速度
183
212
time .Sleep (30 * time .Second )
0 commit comments