如何将图像插入电子邮件正文? [英] How do I Insert an image into email body?

查看:570
本文介绍了如何将图像插入电子邮件正文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用go lang在电子邮件正文中发送图像。
github使用此软件包

I want to send a image in email body using go lang. Used this package from github

https://github.com/scorredoira/email

    err := m.Attach("image.png")
    if err1 != nil {
        fmt.Println(err1)
    }

现在我可以发送图像文件作为附件,但我的需要是发送一个图像文件在电子邮件正文。

Now i am able to send image file as attachment but my need is to send a image file in email body.

提前感谢

推荐答案

您可以使用 Gomail (我是作者)。查看嵌入方法,让您将图像嵌入到电子邮件正文:

You can use Gomail (I'm the author). Have a look at the Embed method which allow you to embed images in the email body:

package main

import "gopkg.in/gomail.v2"

func main() {
    m := gomail.NewMessage()
    m.SetHeader("From", "from@example.com")
    m.SetHeader("To", "to@example.com")
    m.SetHeader("Subject", "Hello!")
    m.Embed("image.png")
    m.SetBody("text/html", `<img src="cid:image.png" alt="My image" />`)

    d := gomail.NewPlainDialer("smtp.example.com", 587, "user", "123456")

    if err := d.DialAndSend(m); err != nil {
        panic(err)
    }
}

这篇关于如何将图像插入电子邮件正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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