I just figured out how to insert email into a Google Apps domain using Google's email migration API. It took me an entire day to figure out how to insert mail that included attachments. Now granted I have no experience with RFC messages or MIME so that's probably why. However I couldn't find any examples online on how to do this. This is the main reason why it took me forever to figure out. The problem with Google's documentation is that the examples they show you are for the simplest of cases possible. Anyway in order to upload mail with the migration API with attachments you need to use MIME multipart messages. This is an extension of a standard RFC822 message. You can read about MIME here. Basically email attachments are nothing more than the file being base64 encoded into the raw message itself. Also with the Google Migration API you can specify certain metadata like whether the message should be in the inbox, starred, or deleted and sent straight to Google Vault. Anyway here is an example of a POST to Google migration api that contains an email with an attachment. It's basically the same as the example from Google's Migration API. The only difference is that instead of the Content-Type being 'text/html' it must be 'multipart/mixed' to include the attachment data.

POST https://www.googleapis.com/upload/email/v2/users/liz@example.com/mail?uploadType=multipart

Content-Type: multipart/related; boundary=\\"part_boundary\\"

--part_boundary
 Content-Type: application/json; charset=UTF-8

{
 'isInbox': 'true'
}

--part_boundary
Content-Type: message/rfc822

Date: Wed, 03 Jan 2013 02:56:03 -0800
 From: admin@example.org
To: liz@example.com
Subject: Hello World!
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=frontier

--frontier
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 8bit

And I think to myself... What a wonderful world!

--frontier
Content-Type: text/plain; name="test.txt"
 Content-Disposition: attachment; filename="test.txt"
Content-Transfer-Encoding: 8bit

Hello A!

--frontier--

--part_boundary--