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
Best Answer
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...
(that's
"Hi Mom!"
encoded as Base64)snip
(that's
<html><body bgcolor="#FFFFFF"><div></div><div><br><br>Sent from my iPad</div></body></html>
as Base64)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. :)