package postcard_test import ( "context" "fmt" "strings" "testing/fstest" "git.golem15.com/golem15/summercms/modules/postcard" ) // mailFS stands in for the plugin's embedded views/mail directory. var mailFS = fstest.MapFS{ "views/mail/welcome.htm": {Data: []byte(`subject = "Welcome, {{ .name }}" layout = "blog" description = "Sent after registration" == Hi **{{ .name }}**, thanks for joining the blog. `)}, "views/mail/layouts/blog.htm": {Data: []byte(`name = "Blog" == {{ .Content }} -- The Acme blog ==
Hi Ada`)) // Header injection is refused before any driver sees the message. err = mailer.Send(context.Background(), postcard.Message{ Template: "acme.blog::mail.welcome", To: []string{"ada@example.com\r\nBcc: all@example.com"}, Vars: map[string]any{"name": "Ada"}, }) fmt.Println(err != nil, len(driver.Messages())) // Output: // blog@example.com [ada@example.com] Welcome, Ada // Hi **Ada**, thanks for joining the blog. // // -- The Acme blog // true // true 1 }