Skip to content

Commit f079ea0

Browse files
author
Winni Neessen
committed
Improve BccFromString to handle spaces and empty addresses
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.
1 parent 03cb09c commit f079ea0

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

msg.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,16 @@ func (m *Msg) BccIgnoreInvalid(rcpts ...string) {
942942
// References:
943943
// - https://datatracker.ietf.org/doc/html/rfc5322#section-3.6.3
944944
func (m *Msg) BccFromString(rcpts string) error {
945-
return m.Bcc(strings.Split(rcpts, ",")...)
945+
src := strings.Split(rcpts, ",")
946+
var dst []string
947+
for _, address := range src {
948+
address = strings.TrimSpace(address)
949+
if address == "" {
950+
continue
951+
}
952+
dst = append(dst, address)
953+
}
954+
return m.Bcc(dst...)
946955
}
947956

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

0 commit comments

Comments
 (0)