-
-
Notifications
You must be signed in to change notification settings - Fork 121
/
sender_alidm.go
50 lines (41 loc) · 1.04 KB
/
sender_alidm.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
package email
import (
"github.com/ArtalkJS/Artalk/internal/config"
"github.com/ArtalkJS/Artalk/internal/log"
aliyun_email "github.com/qwqcode/go-aliyun-email"
"github.com/samber/lo"
)
// AliDMSender implements Sender
type AliDMSender struct {
conf config.AliDMConf
}
var _ Sender = (*AliDMSender)(nil)
// NewAliDMSender 阿里云邮件推送
func NewAliDMSender(conf config.AliDMConf) *AliDMSender {
return &AliDMSender{
conf: conf,
}
}
func (s *AliDMSender) Send(email *Email) bool {
client := aliyun_email.NewClient(
s.conf.AccessKeyId,
s.conf.AccessKeySecret,
s.conf.AccountName,
email.FromName,
lo.If(s.conf.Region == "", aliyun_email.RegionCNHangZhou).Else(s.conf.Region),
)
req := &aliyun_email.SingleRequest{
ReplyToAddress: true,
AddressType: 1,
ToAddress: email.ToAddr,
Subject: email.Subject,
HtmlBody: email.Body,
}
resp, err := client.SingleRequest(req)
if err != nil {
log.Error("[Email] ", "Email sending failed via Aliyun DM", err)
return false
}
log.Debug(resp)
return true
}