Search code examples
iosemailamazon-web-servicesmime

multipart/mixed MIME creation for amazon SES on iOS


Im constructing a MIME essentially from scratch to send emails with attachments using Amazon's SES SDK for iOS. By producing the following MIME and encoding it into a NSData object I am able to receive an email with an attached email:

From: me <from@example.com>
To: to@example.com
Subject: "example subject"
MIME-Version: 1.0
Content-Type: image/png
Content-Disposition: attachment; filename="img.png"
Content-Transfer-Encoding: base64

[giant string of base64 encoded png file omitted for brevity]

However I want to also have a plain text message in the body of the email, but I haven't been able to get my multipart/mixed message with the following format to be parsed correctly. It sends as an email with a "noname" attachment containing all the text after the first boundary.

From: me <from@example.com>
To: to@example.com
Subject: "example subject"
MIME-Version: 1.0
Content-Type: multitype/mixed; boundary="boundary--boundary--boundary"

--boundary--boundary--boundary
Content-Type: text/plain

example plain text

--boundary--boundary--boundary
Content-Type: image/png
Content-Disposition: attachment; filename="img.png"
Content-Transfer-Encoding: base64

[giant string of base64 encoded png file omitted for brevity]

--boundary--boundary--boundary--

Does anyone see something wrong with how I'm formatting the second MIME? Thanks for your help.


Solution

  • You're using the wrong Content-Type. The correct MIME type for a message with this structure is multipart/mixed, not multitype/mixed.