1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Use new mail package instead of an unmintained one (#32682)

Resolve #18664
This commit is contained in:
Lunny Xiao
2024-12-04 14:33:43 -08:00
committed by GitHub
parent 4142397b0b
commit 5ab7aa700f
11 changed files with 133 additions and 71 deletions

View File

@@ -8,12 +8,13 @@ import (
"fmt"
"io"
"net"
"net/smtp"
"os"
"strings"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"github.com/wneessen/go-mail/smtp"
)
// SMTPSender Sender SMTP mail sender
@@ -106,7 +107,7 @@ func (s *SMTPSender) Send(from string, to []string, msg io.WriterTo) error {
if strings.Contains(options, "CRAM-MD5") {
auth = smtp.CRAMMD5Auth(opts.User, opts.Passwd)
} else if strings.Contains(options, "PLAIN") {
auth = smtp.PlainAuth("", opts.User, opts.Passwd, host)
auth = smtp.PlainAuth("", opts.User, opts.Passwd, host, false)
} else if strings.Contains(options, "LOGIN") {
// Patch for AUTH LOGIN
auth = LoginAuth(opts.User, opts.Passwd)
@@ -146,5 +147,10 @@ func (s *SMTPSender) Send(from string, to []string, msg io.WriterTo) error {
return fmt.Errorf("SMTP close failed: %w", err)
}
return client.Quit()
err = client.Quit()
if err != nil {
log.Error("Quit client failed: %v", err)
}
return nil
}