func (m MessageTemplate) Execute(data interface{}) (*Message, error) {
	var buf bytes.Buffer
	out := Message{
		TemplateName: m.Name,
	}
	err := m.SubjectTemplate.Execute(&buf, data)
	if err != nil {
		return nil, err
	}
	out.Subject = buf.String()
	if m.HTMLTemplate != nil {
		buf.Reset()
		err = m.HTMLTemplate.Execute(&buf, data)
		if err != nil {
			return nil, err
		}
		out.HTMLBody = buf.String()
	}
	if m.TextTemplate != nil {
		buf.Reset()
		err = m.TextTemplate.Execute(&buf, data)
		if err != nil {
			return nil, err
		}
		out.TextBody = buf.String()
	}
	if out.TextBody == "" && out.HTMLBody != "" {
		out.TextBody, err = html2text.FromString(out.HTMLBody, html2text.Options{PrettyTables: true})
		if err != nil {
			return nil, err
		}
	}
	return &out, nil
}
Execute the message template, rendering it into a Message.
package email
import (
	"bytes"
	"html/template"
	"github.com/jaytaylor/html2text"
)
type MessageTemplate struct {
	Name            string
	SubjectTemplate *template.Template
	HTMLTemplate    *template.Template
	TextTemplate    *template.Template
}