Move email send from to send func

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-01-21 09:02:29 +08:00
parent 97f5677a97
commit d04f8cdc44
2 changed files with 3 additions and 6 deletions

View File

@@ -13,7 +13,6 @@ import (
type Client struct {
dialer *gomail.Dialer
from string
host string
port int
username string
@@ -26,7 +25,6 @@ func (self *Client) NewSMTPClient() (*Client, error) {
port := viper.GetInt("email.port")
user := viper.GetString("email.username")
pass := viper.GetString("email.password")
from := viper.GetString("email.from")
security := strings.ToLower(viper.GetString("email.security"))
insecure := viper.GetBool("email.insecure_skip_verify")
@@ -45,7 +43,6 @@ func (self *Client) NewSMTPClient() (*Client, error) {
InsecureSkipVerify: insecure,
}
// 安全传输协议配置
switch security {
case "ssl":
dialer.SSL = true
@@ -60,7 +57,6 @@ func (self *Client) NewSMTPClient() (*Client, error) {
return &Client{
dialer: dialer,
from: from,
host: host,
port: port,
username: user,
@@ -69,13 +65,13 @@ func (self *Client) NewSMTPClient() (*Client, error) {
}, nil
}
func (c *Client) Send(to, subject, html string) (string, error) {
func (c *Client) Send(from, to, subject, html string) (string, error) {
if c.dialer == nil {
return "", errors.New("SMTP dialer not initialized")
}
m := gomail.NewMessage()
m.SetHeader("From", c.from)
m.SetHeader("From", from)
m.SetHeader("To", to)
m.SetHeader("Subject", subject)
m.SetBody("text/html", html)

View File

@@ -70,6 +70,7 @@ func Magic(c *gin.Context) {
return
}
emailClient.Send(
"NixCN CMS <cms@yuri.nix.org.cn>",
req.Email,
"NixCN CMS Email Verify",
"<p>Click the link below to verify your email. This link will expire in 10 minutes.</p><a href="+url.String()+">"+url.String()+"</a>",