Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
befaa17426 | |||
fae96eccf5 | |||
4a0ec7bdc9 | |||
331849522f |
39
README.md
@@ -34,14 +34,6 @@ file:
|
|||||||
accessSecret: # oss必填
|
accessSecret: # oss必填
|
||||||
bucketName: # oss必填
|
bucketName: # oss必填
|
||||||
|
|
||||||
# 邮件设置
|
|
||||||
mail:
|
|
||||||
host:
|
|
||||||
port:
|
|
||||||
user:
|
|
||||||
password:
|
|
||||||
skipTls:
|
|
||||||
|
|
||||||
# 一些系统配置
|
# 一些系统配置
|
||||||
wireguard:
|
wireguard:
|
||||||
restartMode: DELAY
|
restartMode: DELAY
|
||||||
@@ -78,14 +70,25 @@ services:
|
|||||||
账户: admin
|
账户: admin
|
||||||
密码: admin123
|
密码: admin123
|
||||||
```
|
```
|
||||||
|
## 配置示例
|
||||||
|
```text
|
||||||
|
1. 邮箱配置如下:
|
||||||
|
code: EMAIL_SMTP
|
||||||
|
配置项:
|
||||||
|
1. host: "xxxx.xxx"
|
||||||
|
2. port: "123"
|
||||||
|
3. user: "haha"
|
||||||
|
4. password: "haha123"
|
||||||
|
5. skipTls: "false"
|
||||||
|
```
|
||||||
|
|
||||||
## 示例
|
## 页面展示
|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|

|
||||||

|

|
@@ -7,6 +7,5 @@ type config struct {
|
|||||||
Database *database `yaml:"database"`
|
Database *database `yaml:"database"`
|
||||||
Cache *cache `yaml:"redis"`
|
Cache *cache `yaml:"redis"`
|
||||||
File *file `yaml:"file"`
|
File *file `yaml:"file"`
|
||||||
Mail *mail `yaml:"email"`
|
|
||||||
Wireguard *wireguard `yaml:"wireguard"`
|
Wireguard *wireguard `yaml:"wireguard"`
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +0,0 @@
|
|||||||
package config
|
|
||||||
|
|
||||||
type mail struct {
|
|
||||||
Host string `json:"host" yaml:"host"`
|
|
||||||
Port int `json:"port" yaml:"port"`
|
|
||||||
User string `json:"user" yaml:"user"`
|
|
||||||
Password string `json:"password" yaml:"password"`
|
|
||||||
SkipTls bool `json:"skipTls" yaml:"skipTls"`
|
|
||||||
}
|
|
Before Width: | Height: | Size: 209 KiB After Width: | Height: | Size: 209 KiB |
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 52 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 49 KiB |
Before Width: | Height: | Size: 34 KiB After Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 59 KiB |
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
@@ -243,7 +243,14 @@ func (ClientApi) Download(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = utils.Mail().SendMail(data.Email, fmt.Sprintf("客户端: %s", data.Name), "请查收附件", outPath)
|
// 获取邮箱配置
|
||||||
|
emailConf, err := service.Setting().GetByCode("EMAIL_SMTP")
|
||||||
|
if err != nil {
|
||||||
|
response.R(c).FailedWithError("获取邮箱配置失败,请先到设置页面的【其他】里面添加code为【EMAIL_SMTP】的具体配置")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = utils.Mail(emailConf).SendMail(data.Email, fmt.Sprintf("客户端: %s", data.Name), "请查收附件", outPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.R(c).FailedWithError("发送邮件失败")
|
response.R(c).FailedWithError("发送邮件失败")
|
||||||
return
|
return
|
||||||
|
@@ -90,6 +90,17 @@ func (s setting) GetAllSetting(blackList []string) (data []vo.SettingItem, err e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetByCode
|
||||||
|
// @description: 获取指定code的配置
|
||||||
|
// @receiver s
|
||||||
|
// @param code
|
||||||
|
// @return data
|
||||||
|
// @return err
|
||||||
|
func (s setting) GetByCode(code string) (data *model.Setting, err error) {
|
||||||
|
err = s.Model(&model.Setting{}).Where("code = ?", code).Take(&data).Error
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Export
|
// Export
|
||||||
// @description: 导出
|
// @description: 导出
|
||||||
// @receiver s
|
// @receiver s
|
||||||
|
@@ -2,28 +2,35 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/jordan-wright/email"
|
"github.com/jordan-wright/email"
|
||||||
|
"github.com/spf13/cast"
|
||||||
"mime"
|
"mime"
|
||||||
"net/smtp"
|
"net/smtp"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"wireguard-ui/config"
|
"wireguard-ui/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
type mail struct {
|
type mail struct {
|
||||||
*email.Email
|
*email.Email
|
||||||
addr string
|
addr string
|
||||||
auth smtp.Auth
|
auth smtp.Auth
|
||||||
|
conf map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Mail() *mail {
|
func Mail(conf *model.Setting) *mail {
|
||||||
|
// 解析配置文件
|
||||||
|
var mailConf = make(map[string]string)
|
||||||
|
_ = json.Unmarshal([]byte(conf.Data), &mailConf)
|
||||||
var m mail
|
var m mail
|
||||||
em := email.NewEmail()
|
em := email.NewEmail()
|
||||||
m.Email = em
|
m.Email = em
|
||||||
m.auth = smtp.PlainAuth("", config.Config.Mail.User, config.Config.Mail.Password, config.Config.Mail.Host)
|
m.auth = smtp.PlainAuth("", mailConf["user"], mailConf["password"], mailConf["host"])
|
||||||
m.addr = fmt.Sprintf("%s:%d", config.Config.Mail.Host, config.Config.Mail.Port)
|
m.addr = fmt.Sprintf("%s:%s", mailConf["host"], mailConf["port"])
|
||||||
|
m.conf = mailConf
|
||||||
return &m
|
return &m
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +54,7 @@ func (m *mail) VerifyConfig() (err error) {
|
|||||||
// @param attacheFilePath
|
// @param attacheFilePath
|
||||||
// @return err
|
// @return err
|
||||||
func (m *mail) SendMail(to, subject, content, attacheFilePath string) (err error) {
|
func (m *mail) SendMail(to, subject, content, attacheFilePath string) (err error) {
|
||||||
m.From = fmt.Sprintf("wg-dashboard <%s>", config.Config.Mail.User)
|
m.From = fmt.Sprintf("wg-dashboard <%s>", m.conf["user"])
|
||||||
m.To = []string{to}
|
m.To = []string{to}
|
||||||
m.Subject = subject
|
m.Subject = subject
|
||||||
m.Text = []byte(content)
|
m.Text = []byte(content)
|
||||||
@@ -61,13 +68,13 @@ func (m *mail) SendMail(to, subject, content, attacheFilePath string) (err error
|
|||||||
atch.Header = emHeader
|
atch.Header = emHeader
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Config.Mail.SkipTls {
|
if cast.ToBool(m.conf["skipTls"]) {
|
||||||
return m.Send(m.addr, m.auth)
|
return m.Send(m.addr, m.auth)
|
||||||
}
|
}
|
||||||
|
|
||||||
tlsConfig := &tls.Config{}
|
tlsConfig := &tls.Config{}
|
||||||
tlsConfig.InsecureSkipVerify = config.Config.Mail.SkipTls
|
tlsConfig.InsecureSkipVerify = cast.ToBool(m.conf["skipTls"])
|
||||||
tlsConfig.ServerName = config.Config.Mail.Host
|
tlsConfig.ServerName = m.conf["host"]
|
||||||
|
|
||||||
return m.SendWithTLS(m.addr, m.auth, tlsConfig)
|
return m.SendWithTLS(m.addr, m.auth, tlsConfig)
|
||||||
}
|
}
|
||||||
|