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.
This isn't a complete solution, but the MIME type for plain text is:
text/plain
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With