I created one csv file, and I also attach it to MFMailComposer, and it shows me my mail composer, but when I send it to the user's email address, it does not show me the attached csv file by email. I used this code to create a csv file and add data to it.
NSMutableString *mainString=[[NSMutableString alloc]initWithString:@""];
for(int i = 0;i<[NameArray count];i++)
{
NSString *string=[indexArray objectAtIndex:i];
string=[string stringByReplacingOccurrencesOfString:@"\"" withString:@"\"\""];
[mainString appendFormat:@"\"%@\"",string];
string=[NameArray objectAtIndex:i];
string=[string stringByReplacingOccurrencesOfString:@"\"" withString:@"\"\""];
[mainString appendFormat:@",\"%@\"",string];
string=[typearray objectAtIndex:i];
string=[string stringByReplacingOccurrencesOfString:@"\"" withString:@"\"\""];
[mainString appendFormat:@",\"%@\"",string];
[mainString appendFormat:@",\"%@\"",string];
[mainString appendFormat:@"\n"];
}
NSLog(@"getdatafor csv:%@",mainString);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectoryPath stringByAppendingPathComponent:@"history.csv"];
NSData* settingsData;
settingsData = [mainString dataUsingEncoding: NSASCIIStringEncoding];
NSError *error;
[settingsData writeToFile:filePath atomically:YES];
NSData *mediaData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMapped error:&error];
NSLog(@"Length:%d Error:%@",[mediaData length],[error localizedDescription]);
here the above code works well, I get [mediaData length]. I am attaching a CSV file from here.
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSString *path = [[NSBundle mainBundle] pathForResource:@"history" ofType:@"csv"];
NSData *myData = [NSData dataWithContentsOfFile:path];
NSString *emailBody = @"history";
[picker setMessageBody:emailBody isHTML:NO];
[picker addAttachmentData:myData mimeType:@"text/cvs" fileName:@"history"];
[self presentModalViewController:picker animated:YES];
[picker release];
The above code also works correctly. it shows me the attached CSV file, but when I send mail by email, the receiver does not receive the attached CSV file at this time. what's wrong with this code.? why does the recipient not receive the attached file.?