diff --git a/README.md b/README.md index 3ce89af..e5cdcd4 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,9 @@ func main() { email.SetBody(mail.TextHTML, htmlBody) + // also you can add body from []byte with SetBodyData, example: + // email.SetBodyData(mail.TextHTML, []byte(htmlBody)) + // add inline email.Attach(&mail.File{FilePath: "/path/to/image.png", Name:"Gopher.png", Inline: true}) diff --git a/email.go b/email.go index 548be50..3b5d00c 100644 --- a/email.go +++ b/email.go @@ -432,6 +432,22 @@ func (email *Email) SetBody(contentType contentType, body string) *Email { return email } +// SetBodyData sets the body of the email message from []byte +func (email *Email) SetBodyData(contentType contentType, body []byte) *Email { + if email.Error != nil { + return email + } + + email.parts = []part{ + { + contentType: contentType.string(), + body: bytes.NewBuffer(body), + }, + } + + return email +} + // AddHeader adds the given "header" with the passed "value". func (email *Email) AddHeader(header string, values ...string) *Email { if email.Error != nil {