tulip/mail/send-template.go

19 lines
540 B
Go
Raw Permalink Normal View History

2023-09-24 18:24:16 +01:00
package mail
import (
"bytes"
"fmt"
"github.com/1f349/tulip/mail/templates"
"github.com/emersion/go-message/mail"
)
func (m *Mail) SendEmailTemplate(templateName, subject, nameOfUser string, to *mail.Address, data map[string]any) error {
2023-10-09 22:48:55 +01:00
var bufHtml, bufTxt bytes.Buffer
templates.RenderMailTemplate(&bufHtml, &bufTxt, templateName, map[string]any{
2023-09-24 18:24:16 +01:00
"ServiceName": m.Name,
"Name": nameOfUser,
"Data": data,
})
2023-10-09 22:48:55 +01:00
return m.SendMail(fmt.Sprintf("%s - %s", subject, m.Name), []*mail.Address{to}, &bufHtml, &bufTxt)
2023-09-24 18:24:16 +01:00
}