是否可以在Google App Engine Go中使用CSS创建电子邮件模板? [英] Is it possible to create email templates with CSS in Google App Engine Go?
问题描述
我正在创建一个GAE Golang应用程序,它将通知用户系统正在发生什么。由于我希望电子邮件看起来不错,我已经在使用HTMLBody。然而,当我创建越来越复杂的电子邮件时,我想开始使用像html / template这样的东西,用CSS等等来打造漂亮的电子邮件。但是,我不知道我可以如何做Template.Execute将其转换成可以发送的HTMLBody字符串。
I am creating a GAE Golang application that will be notifying users of what is happening in the system. Since I want the emails to look nice, I am already using HTMLBody. However, as I'm creating more and more complex emails, I would like to start using something like html/template to crease nice looking emails with CSS and so forth. However, I'm not sure how I can do Template.Execute to turn it into HTMLBody string that can be sent.
如何使用像html / template这样的东西创建要用于appengine / mail的HTML电子邮件?
How can I use something like html/template to create HTML emails to use with appengine/mail ?
推荐答案
您可以将模板渲染为临时字节缓冲区,如下所示: / p>
You can render the template to a temporary byte buffer, like this:
var tmpl = template.Must(template.ParseFiles("templates/email.html"))
buff := new(bytes.Buffer)
if err = tmpl.Execute(buff, struct{ Name string }{"Juliet"}); err != nil {
panic(err.Error())
}
msg := &mail.Message{
Sender: "romeo@montague.com",
To: []string{"Juliet <juliet@capulet.org>"},
Subject: "See you tonight",
Body: "...you put here the non-HTML part...",
HTMLBody: buff.String(),
}
c := appengine.NewContext(r)
if err := mail.Send(c, msg); err != nil {
c.Errorf("Alas, my user, the email failed to sendeth: %v", err)
}
这篇关于是否可以在Google App Engine Go中使用CSS创建电子邮件模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!