Files
goodBaby/drivers/email/ruleConfigChecker.go
T
mei 9b656cebee
Quality check / Web UI (push) Successful in 9m19s
feat(gateway): 优化gateway相关功能
2026-09-12 15:32:27 +08:00

59 lines
1.5 KiB
Go

package email
import (
"fmt"
"net/mail"
"github.com/ssdomei232/goodBaby/internal/meta"
)
// EmailRuleValidator 邮件规则验证器
type EmailRuleValidator struct{}
func (v *EmailRuleValidator) GetType() string {
return RuleType
}
func (v *EmailRuleValidator) Validate(configJSON string) error {
config, err := ParseRuleConfig(configJSON)
if err != nil {
return err
}
if config.Title == "" {
return fmt.Errorf("邮件规则配置中 title 不能为空")
}
if config.Msg == "" {
return fmt.Errorf("邮件规则配置中 msg 不能为空")
}
if len(config.Destinations) == 0 {
return fmt.Errorf("邮件规则配置中 destinations 不能为空")
}
// 验证邮箱地址格式
for _, dest := range config.Destinations {
if _, err := mail.ParseAddress(dest); err != nil {
return fmt.Errorf("无效的邮箱地址: %s", dest)
}
}
return nil
}
func (v *EmailRuleValidator) Meta() meta.RuleMeta {
return meta.RuleMeta{
Type: RuleType,
Label: "发送邮件",
Description: "触发时通过关联的 SMTP 账号向指定地址发送邮件。",
Docs: "docs/email-config.md",
AccountType: AccountType,
Fields: []meta.Field{
{Key: "title", Label: "邮件标题", Type: meta.FieldString, Required: true, GatewayMessage: true},
{Key: "msg", Label: "邮件正文", Type: meta.FieldTextarea, Required: true, GatewayMessage: true},
{Key: "destinations", Label: "收件人", Type: meta.FieldStringList, Required: true, Placeholder: "someone@example.com"},
},
}
}