wneessen / go-mail

📧 Easy to use, yet comprehensive library for sending mails with Go
https://go-mail.dev
MIT License
677 stars 48 forks source link

How to set Content-ID to attached file? #144

Closed dmitam closed 1 year ago

dmitam commented 1 year ago

Is your feature request related to a problem? Please describe.

I need to set Content-ID to use attached image inside the html content. I tried to SetGenHeader on message but it affects all the parts. Seems to be related with #107

Describe the solution you'd like

Another option WithContentId or WithHeader in EmbedFile or AttachFile

Describe alternatives you've considered

No response

Additional context

No response

wneessen commented 1 year ago

Hi @dmitam,

thanks for opening this report. You can actually already do the requested feature with go-mail right now.

Embed your image file like this:

m := mail.NewMsg()
[...]
m.EmbedFile(fn, mail.WithFileName("my_logo.png"))

and in the mail body, then refer to the filename via the oid: keyword:

<img src="cid:my_logo.png" alt="My great Logo" width="150px"/>

The mail client will then inline the logo as expected directly into the mail's html context.

dmitam commented 1 year ago

Thank you! It helped