Skip to content

Commit 25d5f5b

Browse files
committed
New API: SetBodyData
This api set body from []byte. Fix #36
1 parent 9de009c commit 25d5f5b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ func main() {
153153

154154
email.SetBody(mail.TextHTML, htmlBody)
155155

156+
// also you can add body from []byte with SetBodyData, example:
157+
// email.SetBodyData(mail.TextHTML, []byte(htmlBody))
158+
156159
// add inline
157160
email.Attach(&mail.File{FilePath: "/path/to/image.png", Name:"Gopher.png", Inline: true})
158161

email.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,22 @@ func (email *Email) SetBody(contentType contentType, body string) *Email {
432432
return email
433433
}
434434

435+
// SetBodyData sets the body of the email message from []byte
436+
func (email *Email) SetBodyData(contentType contentType, body []byte) *Email {
437+
if email.Error != nil {
438+
return email
439+
}
440+
441+
email.parts = []part{
442+
{
443+
contentType: contentType.string(),
444+
body: bytes.NewBuffer(body),
445+
},
446+
}
447+
448+
return email
449+
}
450+
435451
// AddHeader adds the given "header" with the passed "value".
436452
func (email *Email) AddHeader(header string, values ...string) *Email {
437453
if email.Error != nil {

0 commit comments

Comments
 (0)