5
votes

I am using the following code to send an email with the contents of NSData object(with the variable name: data):

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];

[controller setSubject:@"Subject"];
[controller addAttachmentData:data mimeType:@"application/pdf" fileName:@"Attachment"];
[controller setMessageBody:@"Please find attached the connections for..." isHTML:NO];

controller.mailComposeDelegate = self;
[self presentModalViewController:controller animated:YES];

It adds a UIView generated as a pdf as an attachment and sends the email. It is all good, besides a single problem:

When the email is received, along with the attached pdf, there is another attached .txt file whose contents are: "Sent from my iPad" . If I do not attach the pdf, the "Sent from my iPad" message appears in the body of the email, instead in an attached file.

Does anyone have a clue how this can be resolved ? I do not want the text file to be attached in the message.

Regards,

Petar

1
Hi, is there an update to this issue or any bug reported to Apple which i can refer to?Amit

1 Answers

4
votes

It seems that when you send an email with an attachment, everything in it is wrapped up as a multipart/mixed message, and everything encoded as Base64, including the message body and the signature! So it looks like this...

Content-Type: multipart/mixed;
    boundary="_003_81E0DB72B1F643FBAA40D9BCB66A11E4_"

--_003_81E0DB72B1F643FBAA40D9BCB66A11E4_
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64

SGkgTW9tIQ==

(that's "Hi Mom!" encoded as Base64)

--_003_81E0DB72B1F643FBAA40D9BCB66A11E4_
Content-Type: application/octet-stream; name="MyAttachment.xlsx"
Content-Description: MyAttachment.xlsx
Content-Disposition: attachment; filename="MyAttachment.xlsx"; size=15262
Content-Transfer-Encoding: base64

UEsDBBQABgAIAAAAIQA3Mb2RgAEAAIQFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC

snip

AF81AABkb2NQcm9wcy9hcHAueG1sUEsFBgAAAAANAA0AaAMAACA4AAAAAA==

--_003_81E0DB72B1F643FBAA40D9BCB66A11E4_

Content-Type: text/html; name="ATT00001.htm"
Content-Description: ATT00001.htm
Content-Disposition: attachment; filename="ATT00001.htm"; size=91
Content-Transfer-Encoding: base64

PGh0bWw+PGJvZHkgYmdjb2xvcj0iI0ZGRkZGRiI+PGRpdj48L2Rpdj48ZGl2Pjxicj48YnI+U2VudCBmcm9tIG15IGlQYWQ8L2Rpdj48L2JvZHk+PC9odG1sPg==

(that's <html><body bgcolor="#FFFFFF"><div></div><div><br><br>Sent from my iPad</div></body></html> as Base64)

--_003_81E0DB72B1F643FBAA40D9BCB66A11E4_--

Even if you go to Settings >> Mail, Contacts, Calendars and erase the signature, you still get an empty HTML document attached.

The right long-term answer will probably be to submit this to Apple as a bug and wait. In the meantime, if this is really a showstopper bug, I'd suggest that you generate the entire multipart/mixed email body yourself, without the signature, and see if that fools MFMailComposeViewController into thinking that the email doesn't have an attachment. Personally, I think I'm just going to tell my customer to live with it. :)