如何在Go中发送带有附件的电子邮件

问题描述:

我找到了这个图书馆,并设法在一封空白的电子邮件中发送附件,但不能将文本和附件组合起来。

I have found this library and have managed to send an attachment in an empty email but not to combine text and attachments.

https://github.com/ sloonz / go-mime-message

该怎么办?

How can it be done?

我最终自己实现了它: https://github.com/scorredoira/email

I ended up implementing it myself: https://github.com/scorredoira/email

用法很简单:

Usage is very simple:

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

err := m.Attach("picture.png")
if err != nil {
    log.Println(err)
}

err = email.Send("smtp.gmail.com:587", smtp.PlainAuth("", "user", "password", "smtp.gmail.com"), m)