go-pkgz / email

Email library to send simple messages
https://go-pkgz.umputun.dev/email/
MIT License
21 stars 6 forks source link

Support image embedding from attachments #3

Closed umputun closed 2 years ago

umputun commented 2 years ago

This is about cid and all of this, see for more info this article

umputun commented 2 years ago

related on completion of #1

s0x90 commented 2 years ago

Are there any requirements to api? I'm going to implement something like:

email.Params{From: "me@example.com", To: []string{"to@example.com"}, Subject: "Hello world!", Attachments: []email.Attachment{{path, inline}, {path, inline}})
type Attachment struct {
  path   string
  inline bool
}
umputun commented 2 years ago

the end goal is to produce smth like this:

 To: email@email.de
 Subject: ...
 Content-Type: multipart/related;
 boundary="------------090303020209010600070908"

This is a multi-part message in MIME format.
--------------090303020209010600070908
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 7bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    <img src="cid:part1.06090408.01060107" alt="">
  </body>
</html>

--------------090303020209010600070908
Content-Type: image/png;
 name="moz-screenshot.png"
Content-Transfer-Encoding: base64
Content-ID: <part1.06090408.01060107>
Content-Disposition: inline;
 filename="moz-screenshot.png"

[base64 image data here]

--------------090303020209010600070908--

Having the inline flag for each attached file seems strange, and I'm not sure what the use case for mixed "normal" and inline attachments. I can think of 2 methods here:

umputun commented 2 years ago

another idea - maybe we should leave the current Attachments filed alone, and add another one InlineImages ?

s0x90 commented 2 years ago

Ok, then. I'm adding InlineImages option, and autogenerate CID from filename so that user can add image src to email body, right?

umputun commented 2 years ago

sounds good and easy to use