doq1969 2014-06-07 02:56
浏览 35

是否可以在Google App Engine Go中使用CSS创建电子邮件模板?

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.

How can I use something like html/template to create HTML emails to use with appengine/mail ?

  • 写回答

1条回答 默认 最新

  • douzhan3900 2014-06-07 07:52
    关注

    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)
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度