diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..de5b529 --- /dev/null +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e4f4ba3 --- /dev/null +++ b/go.sum @@ -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= diff --git a/mail.go b/mail.go index 64ed09f..43e6a7d 100644 --- a/mail.go +++ b/mail.go @@ -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" ) diff --git a/mail/mail.go b/mail/mail.go index a66e234..63943f8 100644 --- a/mail/mail.go +++ b/mail/mail.go @@ -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 { @@ -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. diff --git a/main.go b/main.go index b6e830a..bee4e59 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,7 @@ import ( "strings" "text/template" - "github.com/zachlatta/postman/mail" + "github.com/pepa65/postman/mail" "gopkg.in/jordan-wright/email.v2" )