[#7659] fixed SMTP IPv6 format

This commit is contained in:
Gani Georgiev
2026-04-23 21:25:52 +03:00
parent e708f39e1b
commit 69cdda4bf3
2 changed files with 14 additions and 7 deletions

View File

@@ -4,6 +4,8 @@
- Optimized record upsert and preview modals loading to minimize layout jumps. - Optimized record upsert and preview modals loading to minimize layout jumps.
- Fixed SMTP IPv6 network address format ([#7659](https://github.com/pocketbase/pocketbase/issues/7659)).
## v0.37.3 ## v0.37.3

View File

@@ -3,7 +3,9 @@ package mailer
import ( import (
"errors" "errors"
"fmt" "fmt"
"net"
"net/smtp" "net/smtp"
"strconv"
"strings" "strings"
"github.com/domodwyer/mailyak/v3" "github.com/domodwyer/mailyak/v3"
@@ -70,16 +72,18 @@ func (c *SMTPClient) send(m *Message) error {
} }
} }
hostWithPort := net.JoinHostPort(c.Host, strconv.Itoa(c.Port))
// create mail instance // create mail instance
var yak *mailyak.MailYak var yak *mailyak.MailYak
if c.TLS { if c.TLS {
var tlsErr error var tlsErr error
yak, tlsErr = mailyak.NewWithTLS(fmt.Sprintf("%s:%d", c.Host, c.Port), smtpAuth, nil) yak, tlsErr = mailyak.NewWithTLS(hostWithPort, smtpAuth, nil)
if tlsErr != nil { if tlsErr != nil {
return tlsErr return tlsErr
} }
} else { } else {
yak = mailyak.New(fmt.Sprintf("%s:%d", c.Host, c.Port), smtpAuth) yak = mailyak.New(hostWithPort, smtpAuth)
} }
if c.LocalName != "" { if c.LocalName != "" {
@@ -133,15 +137,16 @@ func (c *SMTPClient) send(m *Message) error {
} }
// add custom headers (if any) // add custom headers (if any)
var hasMessageId bool var hasMessageIdHeader bool
for k, v := range m.Headers { for k, v := range m.Headers {
if strings.EqualFold(k, "Message-ID") { if !hasMessageIdHeader && strings.EqualFold(k, "Message-ID") {
hasMessageId = true hasMessageIdHeader = true
} }
yak.AddHeader(k, v) yak.AddHeader(k, v)
} }
if !hasMessageId {
// add a default message id if missing // add a default message id if missing
if !hasMessageIdHeader {
fromParts := strings.Split(m.From.Address, "@") fromParts := strings.Split(m.From.Address, "@")
if len(fromParts) == 2 { if len(fromParts) == 2 {
yak.AddHeader("Message-ID", fmt.Sprintf("<%s@%s>", yak.AddHeader("Message-ID", fmt.Sprintf("<%s@%s>",