feat: 添加版本和构建时间变量 fix: 修正短信队列类型注释错误 style: 清理未使用的代码和测试文件 docs: 更新安装文档中的下载链接 chore: 迁移数据库脚本添加日志和订阅配置
29 lines
701 B
Go
29 lines
701 B
Go
package email
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/perfect-panel/server/pkg/email/smtp"
|
|
"github.com/perfect-panel/server/pkg/logger"
|
|
)
|
|
|
|
type Sender interface {
|
|
Send(to []string, subject, body string) error
|
|
}
|
|
|
|
func NewSender(platform, config, siteName string) (Sender, error) {
|
|
switch parsePlatform(platform) {
|
|
case SMTP:
|
|
cfg := smtp.Config{}
|
|
if err := json.Unmarshal([]byte(config), &cfg); err != nil {
|
|
logger.Error("unmarshal email config failed", logger.Field("error", err.Error()), logger.Field("config", config))
|
|
return nil, err
|
|
}
|
|
cfg.SiteName = siteName
|
|
return smtp.NewClient(&cfg), nil
|
|
default:
|
|
return nil, fmt.Errorf("unsupported platform: %s", platform)
|
|
}
|
|
}
|