Alerting: Add EmbeddedContents as alternative embedding in smtp (#99937)
Adds support for embedding []byte in SmtpClient instead of filenames. This is backwards compatible as it uses a new field EmbeddedContents to add an alternative to the existing EmbeddedFiles which takes filenames.
This commit is contained in:
@@ -132,6 +132,31 @@ func TestSendEmailSync(t *testing.T) {
|
||||
require.Equal(t, []byte("text file content"), file.Content)
|
||||
})
|
||||
|
||||
t.Run("When embedding readers to emails", func(t *testing.T) {
|
||||
ns, mailer := createSut(t, bus)
|
||||
cmd := &SendEmailCommandSync{
|
||||
SendEmailCommand: SendEmailCommand{
|
||||
Subject: "subject",
|
||||
To: []string{"asdf@grafana.com"},
|
||||
SingleEmail: true,
|
||||
Template: "welcome_on_signup",
|
||||
EmbeddedContents: []EmbeddedContent{
|
||||
{Name: "embed.jpg", Content: []byte("image content")},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
err := ns.SendEmailCommandHandlerSync(context.Background(), cmd)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NotEmpty(t, mailer.Sent)
|
||||
sent := mailer.Sent[len(mailer.Sent)-1]
|
||||
require.Len(t, sent.EmbeddedContents, 1)
|
||||
f := sent.EmbeddedContents[0]
|
||||
require.Equal(t, "embed.jpg", f.Name)
|
||||
require.Equal(t, "image content", string(f.Content))
|
||||
})
|
||||
|
||||
t.Run("When SMTP disabled in configuration", func(t *testing.T) {
|
||||
cfg := createSmtpConfig()
|
||||
cfg.Smtp.Enabled = false
|
||||
|
||||
Reference in New Issue
Block a user