首页 > 解决方案 > 将文本和表格添加到 Outlook 正文

问题描述

我想在 Go 中通过 Gomail 在 Outlook 正文中发送 3 行文本和一个表格。该表是从结构数组创建的。

我就是这样把身体送进去的。

m.SetBody("text/html", body)

参考这个链接,Show a table from a slice with my struct Golang,我试图创建一个 html 格式的表格。但它会创建一个 html 文件。

var basenameOpts = []Test {
    Test {
        Entity: "a",
        SourceSystem: "multiple",
        Customer : "Usage for a",
    },
    Test{
        Entity: "test",
        SourceSystem: "b-option",
        Customer : "Usage for b",
    },
}
type PageData struct {
    Title string
    Data []Test
}
func MyStructHandler(w http.ResponseWriter, r *http.Request) {
    data := PageData{
        Text: "My Super Awesome Page of Structs./n/n New line./n/n Next line",
        Data: basenameOpts,
        }
        t := template.Must(template.ParseFiles("./showmystruct.html"))
        t.Execute(w, data)
    }

我应该如何将 html 格式的正文转换为字符串以将其传递给 m.SetBody?

标签: htmlgo

解决方案


推荐阅读