2017-05-03 14:22:05 +08:00
|
|
|
package conf
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
2021-03-23 21:55:50 +08:00
|
|
|
|
2021-03-25 10:42:18 +08:00
|
|
|
"github.com/beego/beego/v2/server/web"
|
2017-05-03 14:22:05 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type SmtpConf struct {
|
2018-01-26 17:17:38 +08:00
|
|
|
EnableMail bool
|
|
|
|
MailNumber int
|
2017-05-03 14:22:05 +08:00
|
|
|
SmtpUserName string
|
2018-01-26 17:17:38 +08:00
|
|
|
SmtpHost string
|
2017-05-03 14:22:05 +08:00
|
|
|
SmtpPassword string
|
2018-01-26 17:17:38 +08:00
|
|
|
SmtpPort int
|
2017-05-03 14:22:05 +08:00
|
|
|
FormUserName string
|
2018-01-26 17:17:38 +08:00
|
|
|
MailExpired int
|
2021-03-23 21:55:50 +08:00
|
|
|
Secure string
|
2017-05-03 14:22:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetMailConfig() *SmtpConf {
|
2021-03-25 10:42:18 +08:00
|
|
|
user_name, _ := web.AppConfig.String("smtp_user_name")
|
|
|
|
password, _ := web.AppConfig.String("smtp_password")
|
|
|
|
smtp_host, _ := web.AppConfig.String("smtp_host")
|
|
|
|
smtp_port := web.AppConfig.DefaultInt("smtp_port", 25)
|
|
|
|
form_user_name, _ := web.AppConfig.String("form_user_name")
|
|
|
|
enable_mail, _ := web.AppConfig.String("enable_mail")
|
|
|
|
mail_number := web.AppConfig.DefaultInt("mail_number", 5)
|
|
|
|
secure := web.AppConfig.DefaultString("secure", "NONE")
|
2017-05-03 14:22:05 +08:00
|
|
|
|
2018-02-02 18:41:27 +08:00
|
|
|
if secure != "NONE" && secure != "LOGIN" && secure != "SSL" {
|
|
|
|
secure = "NONE"
|
|
|
|
}
|
2017-05-03 14:22:05 +08:00
|
|
|
c := &SmtpConf{
|
2018-01-26 17:17:38 +08:00
|
|
|
EnableMail: strings.EqualFold(enable_mail, "true"),
|
|
|
|
MailNumber: mail_number,
|
|
|
|
SmtpUserName: user_name,
|
|
|
|
SmtpHost: smtp_host,
|
|
|
|
SmtpPassword: password,
|
|
|
|
FormUserName: form_user_name,
|
|
|
|
SmtpPort: smtp_port,
|
2021-03-23 21:55:50 +08:00
|
|
|
Secure: secure,
|
2017-05-03 14:22:05 +08:00
|
|
|
}
|
|
|
|
return c
|
2018-01-26 17:17:38 +08:00
|
|
|
}
|