3

I am trying to send out an email with a .csv attachment on the iPad. I am using the MFMailComposer per many examples given which is displayed below. When sending out the email, I can see the correct file attachment in the MFMailComposer window, but when I receive the email, nothing is attached. Any guidance as to what I may be doing wrong would be appreciated. Thank you for your time,

if ([MFMailComposeViewController canSendMail]) {

    MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
    mailViewController.mailComposeDelegate = self;
    [mailViewController setSubject:[NSString stringWithFormat:@"Results for Participant %d.", [delegate participantNumber]]];
    [mailViewController setMessageBody:[NSString stringWithFormat:@"The results for Participant %d in Study: %@ are as follows:", [delegate participantNumber], [[delegate getAccountData:([delegate accountItems] * [delegate accountNumberInUse])] description]] isHTML:NO];

    NSData *textData = [[NSData alloc] initWithContentsOfFile:dataFileName];
    [mailViewController addAttachmentData:textData mimeType:@"text/csv" fileName:[NSString stringWithFormat:@"Participant_Info_#%d.csv", [delegate participantNumber]]];

    [self presentModalViewController:mailViewController animated:YES];
    [mailViewController release];

} 
MarcZero
  • 339
  • 8
  • 20
  • Do you see the attachment in your sent mailbox folder? Also not really relevant to the problem but I think your missing a textData release at the end. – Ernő Simonyi Oct 20 '11 at 09:46

1 Answers1

0

Check the content of the textData variable, also (just guessing from your code) the dataFileName needs to contain a full system path to the file, not just it's name!

NSString *dataFilePath = [[NSBundle mainBundle] pathForResource:dataFileName ofType:nil];
Ondrej Rafaj
  • 4,342
  • 8
  • 42
  • 65