Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(notify): fix tls condition in mail channel #1388

Merged
merged 1 commit into from
Jun 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/notify/controller/messagerequest/smtp/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ func Send(channel *v1.ChannelSMTP, template *v1.TemplateText, email string, vari
log.Debug("msg", log.String("msg", msg[:]))

err = sendMail(fmt.Sprintf("%s:%d", channel.SMTPHost, channel.SMTPPort),
auth, channel.Email, []string{email}, []byte(msg))
auth, channel.Email, []string{email}, []byte(msg), channel.TLS)
if err != nil {
log.Errorf("sendMail error: %v", err)
}
return header, body, err
}

func sendMail(addr string, a smtp.Auth, from string, to []string, msg []byte) error {
host, port, err := net.SplitHostPort(addr)
func sendMail(addr string, a smtp.Auth, from string, to []string, msg []byte, tlsEnabled bool) error {
host, _, err := net.SplitHostPort(addr)
if err != nil {
return fmt.Errorf("invalid address: %s", err)
}
Expand All @@ -79,7 +79,7 @@ func sendMail(addr string, a smtp.Auth, from string, to []string, msg []byte) er
}
var c *smtp.Client

if port == "465" {
if tlsEnabled {
//via TLS
conn, err := tls.Dial("tcp", addr, tlsConfig)
if err != nil {
Expand All @@ -101,7 +101,7 @@ func sendMail(addr string, a smtp.Auth, from string, to []string, msg []byte) er
return err
}

if port != "465" {
if !tlsEnabled {
if ok, _ := c.Extension("STARTTLS"); ok {
if err := c.StartTLS(tlsConfig); err != nil {
return err
Expand Down