1

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

Zigglzworth
  • 6,645
  • 9
  • 68
  • 107
Ganesh
  • 524
  • 1
  • 4
  • 16

1 Answers1

2

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" <bob@example.com>
        To: "Andrew" <andrew@example.com>
        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

Zigglzworth
  • 6,645
  • 9
  • 68
  • 107
  • I have tried using the above logic and I am able to deliver the mail but the attachment is not able to view/download. I actually tried with Image attachment and I found the issue that file is corrupt. Please help me with this issue. – Ganesh Feb 06 '17 at 12:18
  • Check that the content-type is correct and that the image is converted to base64 correctly – Zigglzworth Feb 07 '17 at 15:37