Skip to content

Commit 0261146

Browse files
freedomkk-qfenglaiwei
authored andcommitted
Support TLS and Anonymous (#25)
1 parent fef13fd commit 0261146

File tree

5 files changed

+14
-8
lines changed

5 files changed

+14
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ curl http://$ip:4000/sender/mail -d "tos=a@a.com,b@b.com&subject=xx&content=yy"
4747

4848
## FAQ
4949

50-
1.此插件目前不支持smtp SSL协议(不支持456等安全端口
50+
1.如使用自建邮件系统请设置 skipVerify 为 true 以避免证书校验错误,即使未开启TLS。(因为默认会尝试StartTLS
5151

5252
2.对于126.163等邮箱请控制发信频率以免被封

cfg.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
"addr": "mail.example.com:25",
99
"username": "falcon@example.com",
1010
"password": "123456",
11-
"from": "falcon@example.com"
11+
"from": "falcon@example.com",
12+
"tls":false,
13+
"anonymous":false,
14+
"skipVerify":true
1215
}
1316
}

config/config.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@ type HttpConfig struct {
1515
}
1616

1717
type SmtpConfig struct {
18-
Addr string `json:"addr"`
19-
Username string `json:"username"`
20-
Password string `json:"password"`
21-
From string `json:"from"`
18+
Addr string `json:"addr"`
19+
Username string `json:"username"`
20+
Password string `json:"password"`
21+
From string `json:"from"`
22+
TLS bool `json:"tls"`
23+
Anonymous bool `json:"anonymous"`
24+
SkipVerify bool `json:"skipVerify"`
2225
}
2326

2427
type GlobalConfig struct {

config/const.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package config
22

33
const (
4-
VERSION = "0.0.1"
4+
VERSION = "0.0.2"
55
)

http/mail.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func configProcRoutes() {
2424
content := param.MustString(r, "content")
2525
tos = strings.Replace(tos, ",", ";", -1)
2626

27-
s := smtp.New(cfg.Smtp.Addr, cfg.Smtp.Username, cfg.Smtp.Password)
27+
s := smtp.NewSMTP(cfg.Smtp.Addr, cfg.Smtp.Username, cfg.Smtp.Password, cfg.Smtp.TLS, cfg.Smtp.Anonymous, cfg.Smtp.SkipVerify)
2828
err := s.SendMail(cfg.Smtp.From, tos, subject, content)
2929
if err != nil {
3030
http.Error(w, err.Error(), http.StatusInternalServerError)

0 commit comments

Comments
 (0)