Using Content-ID and cid for Thunderbird Embedded Email Images

I create emails in a PHP application that attach multiple files to HTML email. Some of the files are Excel spreadsheets, some of which are company logos that need to be embedded in HTML, so they load by default using the Content-ID and cid identifiers to link to attached images.

As far as I can tell, my syntax is correct, but images never load inline images (they are attached successfully, however).

From: email@example.com Reply-To: email@example.com MIME-Version: 1.0 Content-type: multipart/mixed;boundary="d0f4ad49cc20d19bf96d4adf9322d567" Message-Id: < 20150421165500.0A5488021B@server > Date: Tue, 21 Apr 2015 12:54:59 -0400 (EDT) --d0f4ad49cc20d19bf96d4adf9322d567 Content-type: text/html; charset=utf-8 Content-transfer-encoding: 8bit <html> Html message goes here, followed by email.<br/> <img src="cid:mylogo" /> </html> --d0f4ad49cc20d19bf96d4adf9322d567 Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; name=excelsheet.xlsx Content-Description: excelsheet.xlsx Content-Disposition: attachment; filename="excelsheet.xlsx"; size=24712; Content-transfer-encoding:base64 [base64 encoded string goes here.] --b19e863e2cf66b40db1d138b7009010c Content-Type: image/jpeg; name="mylogo.jpg" Content-transfer-encoding:base64 Content-ID: <mylogo> Content-Disposition: inline; filename="mylogo.jpg"; size=7579; [base64 encoded string goes here.] --b19e863e2cf66b40db1d138b7009010c-- 

Can someone see the obvious reason why the image will not be embedded as expected?

EDIT

Please note that this behavior is not common to all email clients. So far, only noted in Thunderbird.

+2
source share
1 answer

I noticed two problems:

  • MIME boundary is incompatible. For the first attachment, d0f4ad49cc20d19bf96d4adf9322d567 used, and then b19e863e2cf66b40db1d138b7009010c . Thus, technically, the second application is a β€œpart” of the first application.

    If you replace all b19e863e2cf66b40db1d138b7009010c with d0f4ad49cc20d19bf96d4adf9322d567 Thunderbird correctly identifies the image attachment.

  • Use multipart/related instead of multipart/mixed . (see RFC2387 )

    The multipart / related attribute is used to indicate that each part of the message is a component of the whole. This is for composite objects consisting of several interconnected components - proper display cannot be achieved by individually displaying the component parts. The message consists of the root part (the first, by default), which refers to other parts, which in turn can refer to other parts. Parts of a message usually refer to the header of the "Content-ID" part. (see Wikipedia entry for MIME multipart / related )

+2
source

Source: https://habr.com/ru/post/1259344/


All Articles