From c86cc445ba9989badbd945c8a8d4ad59aabadd8c Mon Sep 17 00:00:00 2001 From: Santiago De la Cruz <51337247+xhit@users.noreply.github.com> Date: Tue, 4 Jul 2023 12:05:47 -0400 Subject: [PATCH] Allow Bcc in header (#81) Fix #38 --- README.md | 4 +++- email.go | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 61e0797..1e0c070 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,9 @@ Go Simple Mail supports: https://pkg.go.dev/github.com/xhit/go-simple-mail/v2?tab=doc -Note: by default duplicated recipients throws an error, from `v2.13.0` you can use `email.AllowDuplicateAddress = true` to avoid the check. +Note 1: by default duplicated recipients throws an error, from `v2.13.0` you can use `email.AllowDuplicateAddress = true` to avoid the check. + +Note 2: by default Bcc header is not set in email. From `v2.14.0` you can use `email.AddBccToHeader = true` to add this. ## Download diff --git a/email.go b/email.go index 2aae703..0054819 100644 --- a/email.go +++ b/email.go @@ -32,6 +32,7 @@ type Email struct { SMTPServer *smtpClient DkimMsg string AllowDuplicateAddress bool + AddBccToHeader bool } /* @@ -349,6 +350,11 @@ func (email *Email) AddAddresses(header string, addresses ...string) *Email { return email } + // add Bcc only if AddBccToHeader is true + if header == "Bcc" && email.AddBccToHeader { + email.headers.Add(header, address.String()) + } + // add all addresses to the headers except for Bcc and Return-Path if header != "Bcc" && header != "Return-Path" { // add the address to the headers