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

View File

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