Skip to content

Commit

Permalink
New API: SetBodyData
Browse files Browse the repository at this point in the history
This api set body from []byte.

Fix #36
  • Loading branch information
xhit committed May 6, 2021
1 parent 9de009c commit 25d5f5b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
16 changes: 16 additions & 0 deletions email.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 25d5f5b

Please sign in to comment.