【问题标题】:multipart email in gogo 中的多部分电子邮件
【发布时间】:2018-05-16 16:19:01
【问题描述】:

我正在尝试使用 golang 发送多部分电子邮件,但我不知道如何创建它们。我知道有一个多部分包,但没有示例如何使用它。

我已经尝试过 mailyak 库,但它不能正常工作。那么,如何使用普通的 golang smtp/multipart 包创建多部分电子邮件?

邮件应该有一个 html 和一个纯文本部分。

【问题讨论】:

  • 查看 tests 以了解 multipart 包的使用示例。

标签: email go multipart


【解决方案1】:

你可能会喜欢这个包https://github.com/scorredoira/email

// compose the message
m := email.NewMessage("Hi", "this is the body")
m.From = mail.Address{Name: "From", Address: "from@example.com"}
m.To = []string{"to@example.com"}

// add attachments
if err := m.Attach("email.go"); err != nil {
    log.Fatal(err)
}

// send it
auth := smtp.PlainAuth("", "from@example.com", "pwd", "smtp.zoho.com")
if err := email.Send("smtp.zoho.com:587", auth, m); err != nil {
    log.Fatal(err)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-11
    • 2019-05-06
    • 2018-07-11
    • 2017-03-19
    • 1970-01-01
    • 1970-01-01
    • 2013-07-13
    相关资源
    最近更新 更多