drewr / postal

Clojure email support
MIT License
586 stars 85 forks source link

embedding attached images in html not working. #108

Closed zendevil closed 4 years ago

zendevil commented 4 years ago

I am sending an email with this body:

:body [
{:type "text/html;charset=utf-8;"
                :content "<div> <img src=\"cid:file.png\"> <div>"
                }
{:type :attachment
                :content (java.io.File. "/path/to/file.png")}
]

My goal is to have the attached file.png be loaded as an image in the html. However, even though the attachment is being sent, the file isn't being loaded in the html. How do I fix this?

drewr commented 4 years ago

You have to actually set the Content-ID and then reference:

:body [{:type "text/html;charset=utf-8;"
        :content "<div> <img src=\"cid:somethingrandom\"> <div>"}
       {:type :attachment
        :content (java.io.File. "/path/to/file.png")
        :content-id "somethingrandom"}]

I didn't test this, and I don't know which clients you're working with. Eg, GMail might also depend on X-Attachment-ID.

zendevil commented 4 years ago

What is X-Attachment-Id and an example please?

drewr commented 4 years ago

That's beyond the scope of postal. Give the suggestion a try and see if it works for you. You can reopen if you find a bug. Thanks!