Smail/backend/utils/validation/notification.go
smail cc749a3dce
Some checks are pending
Security Checks / security (push) Waiting to run
明确显示系统通知地址只发不收的投递失败原因
2026-09-27 00:01:00 +08:00

32 lines
750 B
Go

package validation
import (
"errors"
"strings"
)
var ErrNotificationRecipient = errors.New("notification address does not accept mail")
// 加号不属于可注册账号字符,保留地址不会占用普通用户的邮箱。
const NotificationLocalPart = "notification+system"
func NotificationAddress(domain string) string {
if domain == "" {
return ""
}
return NotificationLocalPart + "@" + domain
}
func IsNotificationAddress(address string, domains []string) bool {
parts := strings.Split(strings.ToLower(strings.TrimSpace(address)), "@")
if len(parts) != 2 || parts[0] != NotificationLocalPart {
return false
}
for _, domain := range domains {
if strings.EqualFold(parts[1], domain) {
return true
}
}
return false
}