Skip to content

Commit

Permalink
Support TLS and Anonymous (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
freedomkk-qfeng authored and laiwei committed Jan 10, 2019
1 parent fef13fd commit 0261146
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ curl http://$ip:4000/sender/mail -d "[email protected],[email protected]&subject=xx&content=yy"

## FAQ

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

2.对于126.163等邮箱请控制发信频率以免被封
5 changes: 4 additions & 1 deletion cfg.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"addr": "mail.example.com:25",
"username": "[email protected]",
"password": "123456",
"from": "[email protected]"
"from": "[email protected]",
"tls":false,
"anonymous":false,
"skipVerify":true
}
}
11 changes: 7 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ type HttpConfig struct {
}

type SmtpConfig struct {
Addr string `json:"addr"`
Username string `json:"username"`
Password string `json:"password"`
From string `json:"from"`
Addr string `json:"addr"`
Username string `json:"username"`
Password string `json:"password"`
From string `json:"from"`
TLS bool `json:"tls"`
Anonymous bool `json:"anonymous"`
SkipVerify bool `json:"skipVerify"`
}

type GlobalConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion config/const.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package config

const (
VERSION = "0.0.1"
VERSION = "0.0.2"
)
2 changes: 1 addition & 1 deletion http/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func configProcRoutes() {
content := param.MustString(r, "content")
tos = strings.Replace(tos, ",", ";", -1)

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

0 comments on commit 0261146

Please sign in to comment.