feat: use embed fs directly to embed the logo in mails
This commit is contained in:
@ -17,6 +17,7 @@
|
||||
package mail
|
||||
|
||||
import (
|
||||
"embed"
|
||||
"io"
|
||||
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
@ -37,6 +38,7 @@ type Opts struct {
|
||||
Boundary string
|
||||
Headers []*header
|
||||
Embeds map[string]io.Reader
|
||||
EmbedFS map[string]*embed.FS
|
||||
}
|
||||
|
||||
// ContentType represents mail content types
|
||||
@ -90,6 +92,13 @@ func getMessage(opts *Opts) *mail.Msg {
|
||||
m.EmbedReader(name, content)
|
||||
}
|
||||
|
||||
for name, fs := range opts.EmbedFS {
|
||||
err := m.EmbedFromEmbedFS(name, fs)
|
||||
if err != nil {
|
||||
log.Errorf("Error embedding %s via embed.FS into mail: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
switch opts.ContentType {
|
||||
case ContentTypePlain:
|
||||
m.SetBodyString("text/plain", opts.Message)
|
||||
|
@ -18,9 +18,9 @@ package notifications
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"embed"
|
||||
_ "embed"
|
||||
templatehtml "html/template"
|
||||
"io"
|
||||
templatetext "text/template"
|
||||
|
||||
"code.vikunja.io/api/pkg/config"
|
||||
@ -87,7 +87,7 @@ const mailTemplateHTML = `
|
||||
`
|
||||
|
||||
//go:embed logo.png
|
||||
var logo []byte
|
||||
var logo embed.FS
|
||||
|
||||
// RenderMail takes a precomposed mail message and renders it into a ready to send mail.Opts object
|
||||
func RenderMail(m *Mail) (mailOpts *mail.Opts, err error) {
|
||||
@ -160,8 +160,8 @@ func RenderMail(m *Mail) (mailOpts *mail.Opts, err error) {
|
||||
Message: plainContent.String(),
|
||||
HTMLMessage: htmlContent.String(),
|
||||
Boundary: boundary,
|
||||
Embeds: map[string]io.Reader{
|
||||
"logo.png": bytes.NewBuffer(logo),
|
||||
EmbedFS: map[string]*embed.FS{
|
||||
"logo.png": &logo,
|
||||
},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user