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

标签 email go smtp

我找到了这个库,并设法在空电子邮件中发送附件,但没有将文本和附件结合起来。

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

怎么做?

最佳答案

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

用法很简单:

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)

关于email - 如何在 Go 中发送带有附件的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11075749/

相关文章:

php - 通过PHP发送多封电子邮件并设置时间间隔

go - 处理 goroutine 时的奇怪事情

performance - SMTP Sampler 在发送消息时执行接收 IOExeception

email - GNU 使用电子邮件从同一服务器发送多个外发帐户,无需 imap

python-3.x - 在 Python 3.4.3 中,如何使用 IMAP 协议(protocol)发送标志 'Seen'

msbuild - MSBuild 中的电子邮件错误 - ReadLinesFromFile "is being used by another process"

c# - 如何在 ASP.NET 中保护将发送的电子邮件分类为垃圾邮件

go - 如何在 Go 中获取系统命令的输出?

go - 反射(reflect)接口(interface)列表

email - 使用 Google 的 SMTP 服务器发送电子邮件