Fix SMTP compatibility issues to support office365 provider

Add support for multiple SMTP providers in `utils/smtp.go`.

* **Provider-specific handling**:
  - Add specific handling for Outlook, QQ, Office365, Resend, and Tencent SMTP policies.
  - Use `switch` statement to set `TLSConfig` based on the SMTP host.
This commit is contained in:
Minghan Zhang 2024-12-03 17:11:51 +08:00
parent 928319acc0
commit 7a467e6e7f

View File

@ -68,12 +68,33 @@ func (s *SmtpPoster) SendMail(to string, subject string, body string) error {
dialer.SSL = true dialer.SSL = true
} }
// outlook starttls policy // Specific handling for different providers
if strings.Contains(s.Host, "outlook") { switch {
case strings.Contains(s.Host, "outlook"):
dialer.TLSConfig = &tls.Config{ dialer.TLSConfig = &tls.Config{
InsecureSkipVerify: false, InsecureSkipVerify: false,
ServerName: s.Host, ServerName: s.Host,
} }
case strings.Contains(s.Host, "qq"):
dialer.TLSConfig = &tls.Config{
InsecureSkipVerify: true,
ServerName: s.Host,
}
case strings.Contains(s.Host, "office365"):
dialer.TLSConfig = &tls.Config{
InsecureSkipVerify: false,
ServerName: s.Host,
}
case strings.Contains(s.Host, "resend"):
dialer.TLSConfig = &tls.Config{
InsecureSkipVerify: true,
ServerName: s.Host,
}
case strings.Contains(s.Host, "tencent"):
dialer.TLSConfig = &tls.Config{
InsecureSkipVerify: true,
ServerName: s.Host,
}
} }
if err := dialer.DialAndSend(message); err != nil { if err := dialer.DialAndSend(message); err != nil {