I'm currently using "gopkg.in/gomail.v2" to send email with following code found here
package main
import (
"bytes"
"fmt"
"gopkg.in/gomail.v2"
)
func main() {
m := gomail.NewMessage()
m.SetHeader("From", "[email protected]")
m.SetHeader("To", "[email protected]")
m.SetAddressHeader("Bcc", "[email protected]", "Bcc Email")
m.SetHeader("Bcc", "[email protected]", "[email protected]")
m.SetHeader("Reply-To", "[email protected]")
m.SetHeader("Subject", "Subject is to gomail to be discussed")
body := `Why is bcc not getting populated`
m.SetBody("text/html", body)
sendMailViaExim(m)
}
func sendMailViaExim(m *gomail.Message) (err error) {
cmd := exec.Command("/usr/sbin/exim", "-t")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
pw, err := cmd.StdinPipe()
if err != nil {
log.Println(err)
return
}
err = cmd.Start()
if err != nil {
log.Println(err)
return
}
var errs [3]error
_, errs[0] = m.WriteTo(pw)
errs[1] = pw.Close()
errs[2] = cmd.Wait()
for _, err = range errs {
if err != nil {
log.Println(err)
return
}
}
return
}
The Above code doesn't send to Bcc emails;
So I logged the info that was being passed to exim -t via following code:
buf := new(bytes.Buffer)
m.WriteTo(buf) //should write entire msg with bcc?
fmt.Println(buf.String())
and the console logged :
$ go run main.go
Mime-Version: 1.0
Date: Mon, 23 Apr 2018 11:15:54 +0530
To: [email protected]
Reply-To: [email protected]
Subject: Subject is to gomail to be discussed
From: [email protected]
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Why is bcc not getting populated
bcc is not getting to the exim -t How do I achieve that without using smtp.
I think it's this (and here is the changelog entry for it).
Still, the logic fixed by the commit above should only apply to actually sending messages—that is, when the package actually speaks with an SMTP server (because, naturally,
Bccshould not be forwarded past the first MTA processing the message (maybe even the first MDA—I'm lazy to read the RFC)).The commit being discussed refers to this part of a relevant RFC which actually offers three different ways to handle
Bccheader fields. So I have no idea whether to actually blame the package author for this change or not.Yet still, this looks like stripping the
Bccheader away even for theMessage.WriteTomethod, which, IMO, is a mistake. The reason I think this is a mistake is as follows:Bccheader fields is clearly not its business—it rather should be delegated to the first "real" mail processing agent.The only relevant issue/pull-request I was able to find is this but it looks like the code was highly refactored after its inclusion so I have no idea whether it introduced what I supposed is a bug or not.
See also this.
TL;DR
I would file an issue in the package's bug tracker.
(If you will do that, please link it there; thanks.)