Skip to content

Commit

Permalink
Improve BccFromString to handle spaces and empty addresses
Browse files Browse the repository at this point in the history
Trim spaces from email addresses and skip empty addresses in BccFromString method. This ensures that the BCC list only includes valid, non-empty email addresses, enhancing email sending reliability.
  • Loading branch information
wneessen committed Oct 26, 2024
1 parent 03cb09c commit f079ea0
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,16 @@ func (m *Msg) BccIgnoreInvalid(rcpts ...string) {
// References:
// - https://datatracker.ietf.org/doc/html/rfc5322#section-3.6.3
func (m *Msg) BccFromString(rcpts string) error {
return m.Bcc(strings.Split(rcpts, ",")...)
src := strings.Split(rcpts, ",")
var dst []string
for _, address := range src {
address = strings.TrimSpace(address)
if address == "" {
continue
}
dst = append(dst, address)
}
return m.Bcc(dst...)
}

// ReplyTo sets the "Reply-To" address for the Msg, specifying where replies should be sent.
Expand Down

0 comments on commit f079ea0

Please sign in to comment.