Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6349687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:39:52+00:00 2026-05-24T21:39:52+00:00

The code below works perfectly to send text (.txt) attachments via the mail application

  • 0

The code below works perfectly to send text (.txt) attachments via the mail application (textfile.csv needs to be modified everywhere with textfile.txt). However when I try to attach csv files it does not work at all (the mail application opens up showing the icon of the textfile.csv but when the mail arrives it has no attachment (nor the data is displayed within the message body). No difference if I change the mime type to “text/plain”. I am puzzled… What am I doing wrong?? Any ideas please?

    - (NSString *)getPath {
   NSString *paths = [NSSearchPathForDirectoriesInDomains
   (NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
   return [paths stringByAppendingPathComponent:@"textfile.csv"];
}

//Saves file to Documents folder
//Method writes a string to a text file
-(void) writeToTextFile{
 //get the documents directory:
 NSArray *paths = NSSearchPathForDirectoriesInDomains
 (NSDocumentDirectory, NSUserDomainMask, YES);
 NSString *documentsDirectory = [paths objectAtIndex:0];


 //make a file name to write the data to using the documents  directory:
 NSString *fileName = [NSString stringWithFormat:@"textfile.csv", 
 documentsDirectory];
 //create content
 NSString *content = @"One,Two,Three,Four,Five";

 //save content to the documents directory
 [content writeToFile:fileName 
     atomically:NO 
    encoding:NSStringEncodingConversionAllowLossy 


 error:nil]; 
}

// Displays an email composition interface inside the application. Populates all the Mail fields.
-(void)displayComposerSheet
{ 
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
 picker.mailComposeDelegate = self; 
 [picker setSubject:@"Subject"];

 // Set up recipients
 NSArray *toRecipients = [NSArray arrayWithObject:@"email@domain.com"];

 [picker setToRecipients:toRecipients];
 // Fill out the email body text
 NSString *emailBody = (@"Data is attached as a .CSV file");

 [picker setMessageBody:emailBody isHTML:NO];

 NSString *SavedDataPath = [self getPath];
 NSString *path = SavedDataPath;

 NSData *myData = [NSData dataWithContentsOfFile:path];
    [picker addAttachmentData:myData mimeType:@"text/csv" fileName:@"textfile.csv"];  

 [self presentModalViewController:picker animated:YES];
    [picker release];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:39:53+00:00Added an answer on May 24, 2026 at 9:39 pm
    NSString *str_mail = @"one,two,three";
    NSData *myData = [str_mail dataUsingEncoding:NSUTF8StringEncoding]; 
    
    MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
    mailController.mailComposeDelegate = self;
    [mailController addAttachmentData:myData mimeType:@"text/csv" fileName:@"myfile"];
    [mailController setMessageBody:@"body" isHTML:NO];
    [self presentModalViewController:mailController animated:YES];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below works great except the email has all the text on one
This code below works in all web browsers except IE: <input type="text" name="passwordLogin" value="Password"
My code is below and works perfectly well when called from onCreate() I have
It works perfectly from the admin site. But the code below doesn't work properly(some
Please can anyone help me out with this problem? This code below works perfectly
The code below works perfectly fine with Firefox, however, I am having problems with
My code below works in firefox perfectly..but not in Safari. When I use the
The code below will show / hide a div on click. It works perfectly
This code below works perfectly for all browsers except IE 7 or 8. <img
the below code works perfectly in FF and CHROME but not in IE. Please

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.