diff --git a/app/src/routes/admin/System.tsx b/app/src/routes/admin/System.tsx index a71262fb..ed374616 100644 --- a/app/src/routes/admin/System.tsx +++ b/app/src/routes/admin/System.tsx @@ -289,9 +289,7 @@ function Mail({ data, dispatch, onChange }: CompProps) { data.port < 65535 && data.username.length > 0 && data.password.length > 0 && - data.from.length > 0 && - data.username.includes("@") && - !/\w+@/.test(data.from) + data.from.length > 0 ); }, [data]); @@ -391,7 +389,6 @@ function Mail({ data, dispatch, onChange }: CompProps) { } className={cn( "transition-all duration-300", - !data.username.includes("@") && `border-red-700`, )} placeholder={t("admin.system.mailUser")} /> @@ -426,9 +423,6 @@ function Mail({ data, dispatch, onChange }: CompProps) { placeholder={`${data.username}@${location.hostname}`} className={cn( "transition-all duration-300", - data.from.length > 0 && - !/\w+@/.test(data.from) && - `border-red-700`, )} /> diff --git a/utils/smtp.go b/utils/smtp.go index ea7b5ace..1e86983b 100644 --- a/utils/smtp.go +++ b/utils/smtp.go @@ -38,10 +38,19 @@ func (s *SmtpPoster) SendMail(to string, subject string, body string) error { return fmt.Errorf("smtp not configured properly") } - dialer := mail.NewDialer(s.Host, s.Port, s.Username, s.Password) - message := mail.NewMessage() + var dialer *mail.Dialer + var from string - message.SetHeader("From", s.From) + if strings.Contains(s.Username, "@") { + dialer = mail.NewDialer(s.Host, s.Port, s.Username, s.Password) + from = s.From + } else { + dialer = mail.NewDialer(s.Host, s.Port, s.From, s.Password) + from = fmt.Sprintf("%s <%s>", s.Username, s.From) + } + + message := mail.NewMessage() + message.SetHeader("From", from) message.SetHeader("To", to) message.SetHeader("Subject", subject) message.SetBody("text/html", body)