Skip to content

Commit

Permalink
chore: smtp compatible (merge pr #214 from @Sh1n3zZ)
Browse files Browse the repository at this point in the history
chore: Compatible with pre-modified SMTP sending method (#174)
  • Loading branch information
zmh-program authored Jun 23, 2024
2 parents f08f442 + 16aba18 commit 481c8ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
8 changes: 1 addition & 7 deletions app/src/routes/admin/System.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,7 @@ function Mail({ data, dispatch, onChange }: CompProps<MailState>) {
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]);

Expand Down Expand Up @@ -391,7 +389,6 @@ function Mail({ data, dispatch, onChange }: CompProps<MailState>) {
}
className={cn(
"transition-all duration-300",
!data.username.includes("@") && `border-red-700`,
)}
placeholder={t("admin.system.mailUser")}
/>
Expand Down Expand Up @@ -426,9 +423,6 @@ function Mail({ data, dispatch, onChange }: CompProps<MailState>) {
placeholder={`${data.username}@${location.hostname}`}
className={cn(
"transition-all duration-300",
data.from.length > 0 &&
!/\w+@/.test(data.from) &&
`border-red-700`,
)}
/>
</ParagraphItem>
Expand Down
15 changes: 12 additions & 3 deletions utils/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 481c8ba

Please sign in to comment.