jordan-wright / email

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

[Enhancement] Add another function export Bytes with all MIME headers field #108

Open sixleaveakkm opened 4 years ago

sixleaveakkm commented 4 years ago

I understand that bcc field (and maybe some other fields) should not be included when exported in most case.

Here is a problem, I try to use this libarary to build the raw message and then send it through Google API. The code is like following:

...

// build message content
e := email.NewEmail()
e.From = "d@example.com"
e.Subject = "foo"
e.Bcc = []string{"a@example.com", "b@example.com"}
e.Text = "bar content"
bytes, _ := e.Bytes()

// build gmail message
message := &gmail.Message{
     Raw: base64.URLEncoding.EncodeToString(bytes),
}
// send , "srv" is gmailService, from is the sender's id
_, err := srv.Users.Messages.Send(from, message).Do()
...

In this condition, all bcc are ignored since the function Bytes only includes needed MIMEHeaders, which bcc is not included.

Would you consider add another function aside Bytes which exports all MIMEHeaders?