如何在Go中发送带有附件的电子邮件 [英] How to send an email with attachments in Go

查看:117
本文介绍了如何在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)

这篇关于如何在Go中发送带有附件的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆