jordan-wright / email

Robust and flexible email library for Go
MIT License
2.61k stars 324 forks source link

Email.Headers.Add("Bcc"…) does not do what one might think #134

Open quite opened 3 years ago

quite commented 3 years ago

If you do Email.Headers.Add("Bcc", "foo@example.com"), you don't get a BCC to that address, but instead an email to the To:, which has a visible header Bcc: foo@example.com. Perhaps this is by design? But Email.Headers.Add("To", "bar@example.com") for example does override Email.To.

bosim commented 3 years ago

I think the library is working correctly as long as you use Email.Bcc = []string{...} then it is being put in SMTP RCPT TO: but not in the mail header part.

See e.g. https://stackoverflow.com/questions/2750211/sending-bcc-emails-using-a-smtp-server/26611044

But I didn't test it.

quite commented 3 years ago

Your reasoning is sound.

I was mostly thinking that if adding To-header by Headers.Add() does overrides envelope-To set earlier, then perhaps Bcc should too.

bosim commented 3 years ago

I didn't think of this, since I read most of email.go, I could remember the logic from there It makes sense. I am not sure it will work ovewriting "To" header, since Email.To is still used as RCPT TO. Should be pretty easy to test, using Email.To = []string{} and setting Email.Headers["To"] to something. It will fail.