Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/pepa65/postman

go 1.21.5

require gopkg.in/jordan-wright/email.v2 v2.0.0-20160301001728-a62870b0c368
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gopkg.in/jordan-wright/email.v2 v2.0.0-20160301001728-a62870b0c368 h1:btqYnSwwBSj/7nX1bPxyHvyXoIaRxS1MZg8v93NLpwY=
gopkg.in/jordan-wright/email.v2 v2.0.0-20160301001728-a62870b0c368/go.mod h1:6YiNdSV9gi2BIEp0u8QxxGZU5nxz4RUJvjZlA9dnOYc=
2 changes: 1 addition & 1 deletion mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
stdMail "net/mail"

"github.com/zachlatta/postman/mail"
"github.com/pepa65/postman/mail"
"gopkg.in/jordan-wright/email.v2"
)

Expand Down
17 changes: 12 additions & 5 deletions mail/mail.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ func NewMailer(username, password, host, port string, skipCertValidation bool) M

func NewMessage(from, to *mail.Address, subject string, files []string, templatePath,
htmlTemplatePath string, context interface{}) (*email.Email, error) {
parsedSubject, err := parseText([]byte(subject), context)
if err != nil {
return nil, err
}

msg := &email.Email{
From: from.String(),
To: []string{to.String()},
Subject: subject,
Subject: string(parsedSubject),
}

for _, file := range files {
Expand Down Expand Up @@ -78,16 +83,18 @@ func parseTemplate(templatePath string, context interface{}) ([]byte, error) {
if err != nil {
return nil, err
}
return parseText(tmplBytes, context)
}

func parseText(tmplBytes []byte, context interface{}) ([]byte, error) {
t := template.Must(template.New("emailBody").Parse(string(tmplBytes)))

var doc bytes.Buffer
err = t.Execute(&doc, context)
var txt bytes.Buffer
err := t.Execute(&txt, context)
if err != nil {
return nil, err
}

return doc.Bytes(), nil
return txt.Bytes(), nil
}

// Send sends an email Message.
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"text/template"

"github.com/zachlatta/postman/mail"
"github.com/pepa65/postman/mail"
"gopkg.in/jordan-wright/email.v2"
)

Expand Down