AWS SES sending mail with attachement using Amazon iOS SDK - ios

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

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

Related

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.
You're using the wrong Content-Type. The correct MIME type for a message with this structure is multipart/mixed, not multitype/mixed.

Activesync: Sendmail command with MIME Type

<?xml version="1.0" encoding="utf-8"?>
<SendMail xmlns="ComposeMail:" xmlns:airsync="AirSync">
<ClientId>34234243</ClientId>
<SaveInSentItems />
<Mime>
From:xxx#.com
To:yyy#.com
Subject:342234 MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: base64
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3350 234234
This is body
</Mime>
</SendMail>
I am working with SendEmail command. I am looking for way to send Mime content to server. I have tried:
Convert the above xml in wbxml and setBOdy HTTP request but server return 103 error code.
Convert the Content betweent to Base64, and append to old string like this:
<?xml version="1.0" encoding="utf-8"?>
<SendMail xmlns="ComposeMail:" xmlns:airsync="AirSync"><ClientId>34234243</ClientId>
<SaveInSentItems/>
<Mime>
text encode base 64
</Mime>
</SendMail>
And convert to wbxml, send to server and receive error code 119 mean :MessageHasNoRecipient
The message being sent contains no recipient.
Anybody help? thanks in advance
I am sure you have a blank character before the "To" keyword in your code.
Let's remove it. Your data before you encode it to base64 encoding must to look like this:
From: xxx#xxx.com
To: xxx#xxx.com
Subject: Mail Subject
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64
Test body
Best regards,
From MS documentation Mime element must be opaque BLOB https://msdn.microsoft.com/en-us/library/gg663453(v=exchg.80).aspx.
So you must write Mime data as CDATA.
<Mime>
<![CDATA[From: xxx#xxx.com
To: xxx#xxx.com
Subject: Mail Subject
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Test body]]>
</Mime>

English Email Displays Chinese-like Characters

I'm using Postal to send emails with an HTML and Text portion.
When the email is sent to Gmail, it is displayed correctly. However, when it is displayed in at least two other email systems (Mail Enable's webmail interface, and an unknown system at a client), the text is rendered as something similar to Chinese. When the client forwards the email back to a Gmail account, the "Chinese" rendering is also visible.
Example email generated:
X-Sender: no-reply#thecompany.com
X-Receiver: therecipient#thecompany.com
MIME-Version: 1.0
From: no-reply#thecompany.com
To: therecipient#thecompany.com
Date: 17 Apr 2013 22:11:25 -0700
Subject: Some Subject
Content-Type: multipart/alternative;
boundary=--boundary_0_83808b99-ef32-4f47-8835-ba4a435a2141
----boundary_0_83808b99-ef32-4f47-8835-ba4a435a2141
Content-Type: text/plain; charset=utf-16
Content-Transfer-Encoding: base64
MIME ENCODED CONTENTS HERE==
----boundary_0_83808b99-ef32-4f47-8835-ba4a435a2141
Content-Type: text/html; charset=utf-16
Content-Transfer-Encoding: base64
MIME ENCODED CONTENTS HERE=
----boundary_0_83808b99-ef32-4f47-8835-ba4a435a2141--
Clearly there is an encoding issue that Gmail somehow sorts out but other email servers do not, but what exactly is the issue?
The charset is specified as utf-16. Is does Postal (or the MVC engine) in fact generate utf-8 output? How can I control the encoding of the output and/or the charset specified in the email header?
The character encoding can be explicitly set to utf-8 by adding the headers
Content-Type: text/plain; charset=utf-8
and
Content-Type: text/html; charset=utf-8
See this article for more information.
NOTE: There is a typo in the article. The text/plain line is missing a semicolon. That is corrected in the example above.

send mail with doc file attachment

i am sending an e-mail with a doc file attachment. I am receiving the mail but with no any attachment.
PHP
$file_resume = '';
if (!empty($_FILES['attachment_file_name']['tmp_name'])) {
$file = $_FILES['attachment_file_name']['name'];
$attachment= file_get_contents($file);
$attachment= chunk_split(base64_encode($attachment));
}
$uid = md5(uniqid(time()));
$headers= "From: no-reply#edu.in"."\r\n";
$headers.= "Reply-To: no-reply#edu.in"."\r\n";
$headers.= "X-Mailer: PHP/" . phpversion()."\r\n Content-Type: multipart/mixed; boundary=\"PHP-mixed-".$uid."\"\r\n";
$headers.= "MIME-Version: 1.0" . "\r\n";
$headers.= "Content-type: text/html; charset=utf-8"."\r\n Content-Disposition: attachment; filename=\"".$attachment."\"\r\n";
$message = $_POST['person_name'];
mail($to,$subject,$message,$headers);
Html
<form id="attachment" action='mailer.php' method='POST' name="attachment" enctype="multipart/form-data">
person name: <input type="text" name="person_name" >
<br />
Attachment : <input id="attachment_file" class="field" style="height: 25px;" type="file" name="attachment_file_name" />
<input id="submit_button" type="submit" value="Send" />
</form>
If you're going to try to manually send an email with attachment(s), you need to get to know the underlying mail text packet that actually represents what you're constructing with the mail() arguments. Unless you comprehend and understand what's going on here, you'll struggle to ever get your email with attachment to send. There's too many sharp edges.
Gmail has a nifty feature on emails to view the original message packet, in plaintext. It's called Show Original. When testing your email script, use a Gmail account if you can so you can inspect the actual email plaintext packet. To Show Original, go to the top, left dropdown triggered by the down arrow next to the reply arrow of an email.
So sending a test email to myself with an image attached, we have what's below. Your mail call, essentially, has to translate into something more or less like this example.
Especially note how the headers start off (the top five headers below you will not handle, except maybe MIME-Version). At the end of that block, you have:
Content-Type: multipart/mixed; boundary=089e0118416874703004d86a5106
The part following the = is a message part boundary, which allows you to add multipart message blocks, including attachment file contents that have been encoded and given appropriate sub-part headers.
So there's:
--089e0118416874703004d86a5106
... message block(s) ...
--089e0118416874703004d86a5106--
There's actually another boundary declared, with:
Content-Type: multipart/alternative; boundary=089e0118416874702b04d86a5104
Which involves the text/plain and text/html dual message formats. This is not required, but many mail clients do it by nature. You can choose either text/plain or text/html, it's up to you and how your comment is formatted.
Next we see:
--089e0118416874703004d86a5106
Content-Type: image/jpeg; name="opinion (2).jpg"
Content-Disposition: attachment; filename="opinion (2).jpg"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_hejlmnuz0
/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAIEBAYIBggICAgICAgICAgKCgoKCgoKCgoKCgoKCgoK
... lots of lines for the encoded file block ...
W5R3W8ajLwrgUJEDGKWN2kWvO5iB7qdKwB6MwwfqVrQKcObveZxZBtQNCp0vc//Z
--089e0118416874703004d86a5106--
Note that the boundary's have a trailing -- at the end of their blocks (not each block).
Take a look below and compare that to the code that luk3thomas has in his answer. Try sending a very simple email message to yourself, and compare that to an attachment-formatted email:
mail('your#email.com', 'Simple mail test', 'Test message body content.');`
You should start to get the idea what's required to send emails with attachments included. The thing is, formatting an email packet for sending is very particular and little things can cause it to fail. So you have to pay attention.
MIME-Version: 1.0
Received: by 10.50.40.164 with HTTP; Thu, 21 Mar 2013 00:30:51 -0700 (PDT)
Date: Thu, 21 Mar 2013 02:30:51 -0500
Delivered-To: [redacted]#gmail.com
Message-ID: <CAKJE7RAH3+ZgN+86xykJrrzVaHK3waPD-a-OXbSDe3FGgcQrMw#mail.gmail.com>
Subject: Test of email with attachment for plaintext
From: Jared Farrish <[redacted]#gmail.com>
To: Jared Farrish <[redacted]#gmail.com>
Content-Type: multipart/mixed; boundary=089e0118416874703004d86a5106
--089e0118416874703004d86a5106
Content-Type: multipart/alternative; boundary=089e0118416874702b04d86a5104
--089e0118416874702b04d86a5104
Content-Type: text/plain; charset=UTF-8
This is the body of the email message.
--089e0118416874702b04d86a5104
Content-Type: text/html; charset=UTF-8
<div dir="ltr">This is the body of the email message.<br></div>
--089e0118416874702b04d86a5104--
--089e0118416874703004d86a5106
Content-Type: image/jpeg; name="opinion (2).jpg"
Content-Disposition: attachment; filename="opinion (2).jpg"
Content-Transfer-Encoding: base64
X-Attachment-Id: f_hejlmnuz0
/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAIEBAYIBggICAgICAgICAgKCgoKCgoKCgoKCgoKCgoK
CgoKCgwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz/2wBDAQIICBAQEBAQEBAgICAgIEBAQEBA
QEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQED/wgARCAEsASwDASIA
AhEBAxEB/8QAHQAAAgIDAQEBAAAAAAAAAAAABgcFCAIDBAkAAf/EABsBAAMBAQEBAQAAAAAAAAAA
[-- snip many lines of base64 file contents --]
yGrjmAV5jlw7j5RFebDQu8RG2rLa/up9x/xHOU5eppGo7lm3uDTz6w5XxBYgB7ruYJFwW/2PiD9q
XjDEturp55IeLGM36+Tlz8JY6v8AXGhta9/4Ih62UvuWHuP3DfOg/wAGFg/g0mNKnahdifSKKua+
h0likOlp+yFa2FgP0rtOReVitRTIiUuJSjw6JpN4thVyhRdZ8EE/aYzn523NZeJYu7judhllHo0g
W5R3W8ajLwrgUJEDGKWN2kWvO5iB7qdKwB6MwwfqVrQKcObveZxZBtQNCp0vc//Z
--089e0118416874703004d86a5106--
You'll need to add the attachment into the body of the email message. Try something like this:
$random_hash = md5(time());
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
$headers .= "\r\nMIME-Version 1.0";
$attachment = chunk_split(base64_encode(file_get_contents($filename)));
$message =
"--PHP-alt-$random_hash
Content-Type: text/plain
Dear Same,
We would like to thank you for your registration to be held on Saturday August 25, 2012 at the....
--PHP-alt-$random_hash
Content-Type: application/pdf; name=$filename
Content-Transfer-Encoding: base64
Content-Disposition: attachment
$attachment
--PHP-alt-$random_hash--";
#mail($to, $subject, $message, $headers);

pdf attachment not working rails3

In rails 3 when we attach pdf document in email through action mailer,
that pdf is not come as a attachment in e-mail, its come in body like
Date: Wed, 29 Dec 2010 19:56:12 +0530
Mime-Version: 1.0
Content-Type: application/pdf;
charset=UTF-8;
filename=free_book.pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename=free_book.pdf
Content-ID: <4d1b450431abc_### #BHUSHANF.mail>
JVBERi0xLjMKJf////8KMSAwIG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VEoKRVQKClEKCmVuZHN0cmVhbQpl
bmRvYmoKNSAwIG9iago8PCAvVHlwZSAvUGFnZQovUGFyZW50IDIgMCBSCi9S
ZXNvdXJjZXMgPDwgL1Byb2NTZXQgWy9QREYgL1RleHQgL0ltYWdlQiAvSW1h
Z2VDIC9JbWFnZUldCi9Gb250IDw8IC9GMS4wIDYgMCBSCj4+Cj4+Ci9NZWRp
YUJveCBbMCAwIDYxMi4wIDc5Mi4wXQovQ29udGVudHMgNCAwIFIKPj4KZW5k
b2JqCjYgMCBvYmoKPDwgL0VuY29kaW5nIC9XaW5BbnNpRW5jb2RpbmcKL1R5
cGUgL0ZvbnQKL0Jhc2VGb250IC9IZWx2ZXRpY2EKL1N1YnR5cGUgL1R5cGUx
Cj4+CmVuZG9iagp4cmVmCjAgNwowMDAwMDAwMDAwIDY1NTM1IGYgCjAwMDAw
MDAwMTUgMDAwMDAgbiAKMDAwMDAwMDA3MSAwMDAwMCBuIAowMDAwMDAwMTI4
IDAwMDAwIG4gCjAwMDAwMDAxNzcgMDAwMDAgbiAKMDAwMDAwMDgxNiAwMDAw
MCBuIAowMDAwMDAwOTk0IDAwMDAwIG4gCnRyYWlsZXIKPDwgL1Jvb3QgMyAw
IFIKL0luZm8gMSAwIFIKL1NpemUgNwo+PgpzdGFydHhyZWYKMTA5MQolJUVP
Rgo=
You probably did not define a view for the action. I had the same problem as you and by creating a view in app/views/test_mailer/view.text.erb the need for a :body was rendered obsolete.
This can happen when the :body tag is not present in the mail function.

Resources