duanke9540 2012-03-30 20:36
浏览 727

如何使用带有HTML格式的正文的Go发送电子邮件?

This seems like a very common need, but I didn't find any good guides when I searched for it.

  • 写回答

3条回答 默认 最新

  • dongwei3172 2012-03-30 23:16
    关注

    Assuming that you're using the net/smtp package and so the smtp.SendMail function, you just need to declare the MIME type in your message.

    mime := "MIME-version: 1.0;
    Content-Type: text/html; charset=\"UTF-8\";
    
    ";
    subject := "Subject: Test email from Go!
    "
    msg := []byte(subject + mime + "<html><body><h1>Hello World!</h1></body></html>")
    
    smtp.SendMail(server, auth, from, to, msg)
    

    Hope this helps =)

    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退