jordan-wright / email

Robust and flexible email library for Go
MIT License
2.65k stars 321 forks source link

Q: how to use inline assets? #130

Closed ivanjaros closed 3 years ago

ivanjaros commented 3 years ago

The assets have this flag "related to html" which causes them to be treated as email attachments or as inline assets. But I am not sure how I am supposed to use the inline assets in the html body for example? Any examples?

bosim commented 3 years ago

Just use

e := email.NewEmail()
...
at := e.Attach(buffer, "img.png", "image/png")
at.HTMLRelated = true
...

With a recent change #135 it is being marked as inline. In the HTML part you can reference the image using <img src="cid:img.png"/>.

See email_test.go: TestEmailWithHTMLAttachments().

ivanjaros commented 3 years ago

<img src="cid:img.png"/> is what i was asking about.