I'm running into an odd problem with sending inline attachments via Gmail's API. I am using the .NET client (version 1.10.0). The email is a reply to a message I've received with an inline attachment, so the attachment is part of the quoted block in the reply.
Here's the raw MIME message that I'm sending out:
From: ...
To: ...
Date: Fri, 01 Jul 2016 11:48:29 -0700
Subject: Re: attachment test #2
Message-Id: ...
In-Reply-To:...
References: ...
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-JOa+9Bw0690XCFj1YCPc1Q=="
--=-JOa+9Bw0690XCFj1YCPc1Q==
Content-Type: text/html; charset=utf-8
Content-Id: <W4PKNTOPLYT4.32IVHE45EWK21@BILLRAVDIN9F02>
<div style="font-family: Helvetica, Arial, sans-serif;">back atcha.<div><br>On Fri, Jul 01, 2016 at 11:38 AM, ... wrote:<div>[Omitted for clarity]<img height="168" width="300" src="cid:8AF6D64A-9AAD-4E54-8998-5F08C42F537F"></span></div><br></div></div></div></div></div>
--=-JOa+9Bw0690XCFj1YCPc1Q==
Content-Type: image/jpeg; name="ha ha.jpeg"
Content-Disposition: inline; filename="ha ha.jpeg"
Content-Transfer-Encoding: base64
Content-Id: <8AF6D64A-9AAD-4E54-8998-5F08C42F537F>
[Base64 encoded attachment]
--=-JOa+9Bw0690XCFj1YCPc1Q==--
Note above the content disposition on the mime part for the inline attachment:
Content-Disposition: inline; filename="ha ha.jpeg"
Here's what the MIME headers on the inline attachment part look like when it comes in:
Content-Type: image/jpeg; name="ha ha.jpeg"
Content-Disposition: attachment; filename="ha ha.jpeg"
Content-Transfer-Encoding: base64
Content-ID: <8AF6D64A-9AAD-4E54-8998-5F08C42F537F>
X-Attachment-Id: 594301951148d672_0.1
My question is: why is the Content-Disposition now rewritten as attachment rather than inline?
I've found that when viewing the email in my browser, it appears as expected. But when viewing with my Mac's Mail client, the inline attachment appears in the email twice. I suspect that the change in the content disposition might be the reason- any light you can shed on this would be much appreciated!
I know this question is quite old but I was running into the same issue and finally found the reason. It seems that Gmail does not support setting the Content-Disposition to inline for multipart/mixed parts of the MIME.
My MIME was structured in a similar way to the example in the original question by placing the inline image in a multipart/mixed part which ended up being changed to attachment and then being incorrectly displayed as an attached file by some email clients.
By placing the inline image in a multipart/related part with the message body Gmail stopped changing the Content-Disposition and the image was handled correctly.
Here is the MIME structure I have used for it to work (note that in my case I also have a regular file attached to the email):
MIME-Version: 1.0
[...]
--MIXED
--RELATED
--ALTERNATIVE
<Plain text version of the email>
--ALTERNATIVE
<HTML Version of the email>
--ALTERNATIVE--
--RELATED
<Inline image>
--RELATED--
--MIXED
<Attachment file>
--MIXED--
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With