@@ -16,20 +16,21 @@ import (
1616
1717// Email represents an email message.
1818type Email struct {
19- from string
20- sender string
21- replyTo string
22- returnPath string
23- recipients []string
24- headers textproto.MIMEHeader
25- parts []part
26- attachments []* File
27- inlines []* File
28- Charset string
29- Encoding encoding
30- Error error
31- SMTPServer * smtpClient
32- DkimMsg string
19+ from string
20+ sender string
21+ replyTo string
22+ returnPath string
23+ recipients []string
24+ headers textproto.MIMEHeader
25+ parts []part
26+ attachments []* File
27+ inlines []* File
28+ Charset string
29+ Encoding encoding
30+ Error error
31+ SMTPServer * smtpClient
32+ DkimMsg string
33+ AllowDuplicateAddress bool
3334}
3435
3536/*
@@ -317,7 +318,7 @@ func (email *Email) AddAddresses(header string, addresses ...string) *Email {
317318 email .returnPath = address .Address
318319 default :
319320 // check that the address was added to the recipients list
320- email .recipients , err = addAddress (email .recipients , address .Address )
321+ email .recipients , err = addAddress (email .recipients , address .Address , email . AllowDuplicateAddress )
321322 if err != nil {
322323 email .Error = errors .New ("Mail Error: " + err .Error () + "; Header: [" + header + "] Address: [" + addresses [i ] + "]" )
323324 return email
@@ -343,11 +344,13 @@ func (email *Email) AddAddresses(header string, addresses ...string) *Email {
343344}
344345
345346// addAddress adds an address to the address list if it hasn't already been added
346- func addAddress (addressList []string , address string ) ([]string , error ) {
347- // loop through the address list to check for dups
348- for _ , a := range addressList {
349- if address == a {
350- return addressList , errors .New ("Mail Error: Address: [" + address + "] has already been added" )
347+ func addAddress (addressList []string , address string , allowDuplicateAddress bool ) ([]string , error ) {
348+ if ! allowDuplicateAddress {
349+ // loop through the address list to check for dups
350+ for _ , a := range addressList {
351+ if address == a {
352+ return addressList , errors .New ("Mail Error: Address: [" + address + "] has already been added" )
353+ }
351354 }
352355 }
353356
0 commit comments