Ganesh
Ganesh

Reputation: 524

AWS SES sending mail with attachement using Amazon iOS SDK

Does anyone know how to send a mail with an attachment using Amazon SES with the iOS SDK.

Upvotes: 1

Views: 562

Answers (1)

Zigglzworth
Zigglzworth

Reputation: 6813

To send an email with SES using the iOS SDK you need to create a AWSSESSendRawEmailRequest and make sure that the rawMessage (AWSSESRawMessage) data format complies with Internet email standards regarding email header fields, MIME types, MIME encoding, and base64 encoding.

This means converting the NSData of your attachment to a base64 string and inserting it in the raw email string with all the headers etc.

Such a string may look something like this:

        From: "Bob" <[email protected]>
        To: "Andrew" <[email protected]>
        Date: Wed, 2 Mar 2011 11:39:34 -0800
        Subject: Customer service contact info
        Accept-Language: en-US
        Content-Language: en-US
        Content-Type: multipart/mixed;
            boundary="_003_97DCB304C5294779BEBCFC8357FCC4D2"
        MIME-Version: 1.0

        --_003_97DCB304C5294779BEBCFC8357FCC4D2
        Content-Type: text/plain; charset="us-ascii"
        Content-Transfer-Encoding: quoted-printable

        Hi Andrew.  Here are the customer service names and telephone numbers I promised you. 

        See attached.

        -Bob

        --_003_97DCB304C5294779BEBCFC8357FCC4D2
        Content-Type: text/plain; name="cust-serv.txt"
        Content-Description: cust-serv.txt
        Content-Disposition: attachment; filename="cust-serv.txt"; size=1180;
            creation-date="Wed, 02 Mar 2011 11:39:39 GMT";
            modification-date="Wed, 02 Mar 2011 11:39:39 GMT"
        Content-Transfer-Encoding: base64

        TWFyeSBEYXZpcyAtICgzMjEpIDU1NS03NDY1DQpDYXJsIFRob21hcyAtICgzMjEpIDU1NS01MjM1
        DQpTYW0gRmFycmlzIC0gKDMyMSkgNTU1LTIxMzQ=

        --_003_97DCB304C5294779BEBCFC8357FCC4D2

Note that AWSSESRawMessage has a data (NSData) property so this string will need to be converted to NSData before using it in AWSSESRawMessage

Upvotes: 2

Related Questions