mirror of
https://github.com/certimate-go/certimate.git
synced 2026-09-03 14:27:48 +08:00
feat(provider): allow optional username and password in email notifier
This commit is contained in:
@@ -63,9 +63,6 @@ func (c *Client) Send(ctx context.Context, msg *Message) error {
|
||||
|
||||
func createSmtpClient(config *Config) (*mail.Client, error) {
|
||||
clientOptions := []mail.Option{
|
||||
mail.WithSMTPAuth(mail.SMTPAuthAutoDiscover),
|
||||
mail.WithUsername(config.Username),
|
||||
mail.WithPassword(config.Password),
|
||||
mail.WithTimeout(time.Second * 30),
|
||||
}
|
||||
|
||||
@@ -87,13 +84,23 @@ func createSmtpClient(config *Config) (*mail.Client, error) {
|
||||
tlsConfig.ServerName = config.Host
|
||||
}
|
||||
|
||||
clientOptions = append(clientOptions, mail.WithSSL())
|
||||
clientOptions = append(clientOptions, mail.WithTLSConfig(tlsConfig))
|
||||
clientOptions = append(clientOptions, mail.WithTLSPolicy(mail.TLSMandatory))
|
||||
clientOptions = append(clientOptions,
|
||||
mail.WithSSL(),
|
||||
mail.WithTLSConfig(tlsConfig),
|
||||
mail.WithTLSPolicy(mail.TLSMandatory),
|
||||
)
|
||||
} else {
|
||||
clientOptions = append(clientOptions, mail.WithTLSPolicy(mail.TLSOpportunistic))
|
||||
}
|
||||
|
||||
if config.Username != "" || config.Password != "" {
|
||||
clientOptions = append(clientOptions,
|
||||
mail.WithSMTPAuth(mail.SMTPAuthAutoDiscover),
|
||||
mail.WithUsername(config.Username),
|
||||
mail.WithPassword(config.Password),
|
||||
)
|
||||
}
|
||||
|
||||
client, err := mail.NewClient(config.Host, clientOptions...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -20,9 +20,9 @@ type NotifierConfig struct {
|
||||
// 是否启用 TLS。
|
||||
SmtpTls bool `json:"smtpTls"`
|
||||
// 用户名。
|
||||
Username string `json:"username"`
|
||||
Username string `json:"username,omitempty"`
|
||||
// 密码。
|
||||
Password string `json:"password"`
|
||||
Password string `json:"password,omitempty"`
|
||||
// 发件人邮箱。
|
||||
SenderAddress string `json:"senderAddress"`
|
||||
// 发件人显示名称。
|
||||
|
||||
@@ -130,8 +130,8 @@ const getSchema = ({ i18n = getI18n() }: { i18n: ReturnType<typeof getI18n> }) =
|
||||
smtpHost: z.string().refine((v) => isHostname(v), t("common.errmsg.host_invalid")),
|
||||
smtpPort: z.coerce.number().refine((v) => isPortNumber(v), t("common.errmsg.port_invalid")),
|
||||
smtpTls: z.boolean().nullish(),
|
||||
username: z.string().nonempty(),
|
||||
password: z.string().nonempty(),
|
||||
username: z.string().nullish(),
|
||||
password: z.string().nullish(),
|
||||
senderAddress: z.email(),
|
||||
senderName: z.string().nullish(),
|
||||
receiverAddress: z.email().or(z.literal("")).nullish(),
|
||||
|
||||
@@ -529,12 +529,12 @@
|
||||
}
|
||||
},
|
||||
"email_username": {
|
||||
"label": "Username",
|
||||
"placeholder": "please enter username"
|
||||
"label": "Username (Optional)",
|
||||
"placeholder": "please enter SMTP username"
|
||||
},
|
||||
"email_password": {
|
||||
"label": "Password",
|
||||
"placeholder": "please enter password"
|
||||
"label": "Password (Optional)",
|
||||
"placeholder": "please enter SMTP password"
|
||||
},
|
||||
"email_sender_address": {
|
||||
"label": "Sender email address",
|
||||
|
||||
@@ -527,12 +527,12 @@
|
||||
}
|
||||
},
|
||||
"email_username": {
|
||||
"label": "用户名",
|
||||
"placeholder": "请输入用户名"
|
||||
"label": "用户名(可选)",
|
||||
"placeholder": "请输入 SMTP 用户名"
|
||||
},
|
||||
"email_password": {
|
||||
"label": "密码",
|
||||
"placeholder": "请输入密码"
|
||||
"label": "密码(可选)",
|
||||
"placeholder": "请输入 SMTP 密码"
|
||||
},
|
||||
"email_sender_address": {
|
||||
"label": "发件人邮箱",
|
||||
|
||||
Reference in New Issue
Block a user