I've been trying to use MFMailComposer to send a text file with encrypted data within. The problem is my attachment never shows up when when the email arrives in the inbox. Instead, a line of "<br/><br/>
" is always present. I'm assuming is has something to do with the mime type and the receivers mail server not know how to read the data but I just can't figure out a solution.
Anyone come across this before and have a solution?
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
mailController.mailComposeDelegate =self;
[mailController setSubject:@"Records"];
[mailController setMessageBody:@"" isHTML:YES];
[mailController addAttachmentData:dataToBeEncrypted mimeType:@"text/plain" fileName:@"Records.txt"];
[self presentModalViewController:mailController animated:YES];
[mailController release];
} else {
//Pop up a notification
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Could not send email. Verify Internet conneciton and try again." delegate:nil cancelButtonTitle:@"Done" otherButtonTitles:nil];
[alert show];
[alert release];
}
Thanks for any help you can give!
Think I got a fix. I just took a shot in the dark after seeing another example and it seemed to work. For mimetype, I just put @"mime".
I'm a little weary of it, so I'll have to do some more testing to make sure the file always comes out correct.
来源:https://stackoverflow.com/questions/3295886/attaching-plain-text-file-using-mfmailcomposer-in-iphone-sdk