Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

attaching a text file to an email

I successfully created a txt file (i.e. the file exists and opens), I would like to attach it to an email that I am successfully generating (i.e. the email opens and I can put text into the email etc. and send it). Here is the code I have now for performing the attachment:

// Attach a file to the email
NSString *path = [self dataFilePath:(@"myFile.txt")];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"text/plain" fileName:@"myFile"];

The dataFilePath is a method I use to get the path for a file, it works fine as I use it often. The above code puts a < br/ > < br/ >, then has the text from the text file with a few more < br/ > < br/ > ..breaks in there... so this doesn't actually attach the file it pastes it in the email text... I would like to attach the file.

I copied/modified this code from other posts on stackoverflow and I'm having a hard time finding info on apple's site. Note: I'm not sure what the mimeType is for a txt file, as their website (www.iana.org) doesn't denote a txt...???

Update: Changed to updated code, and Thanks for confirming that "plain" was the correct choice for the mimeType.

like image 962
driveguy Avatar asked Aug 07 '09 03:08

driveguy


1 Answers

This isn't a complete solution, but the MIME type for plain text is:

text/plain
like image 112
Greg Hewgill Avatar answered Oct 13 '22 01:10

Greg Hewgill