Skip to content

Commit

Permalink
feat: option for skip email tls verification
Browse files Browse the repository at this point in the history
  • Loading branch information
heilmela committed Jun 10, 2024
1 parent e4a4a91 commit 5b4acd3
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion service/mail/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mail

import (
"context"
"crypto/tls"
"net"
"net/textproto"
"strconv"
Expand All @@ -19,6 +20,7 @@ type Mail struct {
pass string
receiverAddresses []string
headers textproto.MIMEHeader
tls *tls.Config
}

// New returns a new instance of a Mail notification service.
Expand Down Expand Up @@ -71,6 +73,14 @@ func (m *Mail) AddHeader(name, value string) {
m.headers.Add(name, value)
}

func (m *Mail) InsecureSkipVerify(enable bool) {
if m.tls == nil {
host, _, _ := net.SplitHostPort(m.smtpHostAddr)
m.tls = &tls.Config{ServerName: host}
}
m.tls.InsecureSkipVerify = enable
}

func (m *Mail) newEmail(subject, message string) *mail.Message {
msg := mail.NewMessage()
msg.SetHeader("From", m.senderAddress)
Expand Down Expand Up @@ -114,7 +124,9 @@ func (m Mail) Send(ctx context.Context, subject, message string) error {
}

d := mail.NewDialer(host, port, m.user, m.pass)

if m.tls != nil {
d.TLSConfig = m.tls
}
if deadline, ok := ctx.Deadline(); ok {
timeout := time.Until(deadline)
if timeout > 0 {
Expand Down

0 comments on commit 5b4acd3

Please sign in to comment.