go 中的多部分电子邮件

multipart email in go

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

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

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

你可能会喜欢这个包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)
}