objective-c – Format RTF file to be sent as body using MFMailComposeViewController


I have to send a text report (with formatting) that I put in an RTF file inside my project.

When I'm going to define the email body using the method below, the formatting of the RTF file is not recognized by MFMailComposeViewController.

Here's the code I'm using and the NSString returned from my RTF file:

NSString *path = [[NSBundle mainBundle] pathForResource:@"relatorio"

NSString *emailBody = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];

[picker setMessageBody:emailBody isHTML:NO];

I've already tried several encodings and it didn't change the emailBody content, below is the beginning of the NSString emailBody:

{\fonttbl\f0\fswiss\fcharset0 Helvetica;}

\f0\b\fs24 \cf0 Relat\'f3rio \
\cf0 Desenvolvido por Finaltap\

Putting in HTML is not an option as the report is very large and was taken from an MS Word file.

Any idea???


The simplest idea is to send it as an attachment. If you don't need to make changes at runtime, it's an extremely simple solution and should solve your problem.

You will start an NSData with the contents of the file and pass it in the picker addAttachmentData . Done!

Now if you really need to put the content directly into the body of the email, I believe some conversions to HTML will be needed. You say that changing the source file is not an option, but I will mention the possibility of doing this conversion at runtime.

The NSAttributedString has an initWithData that supports receiving an NSData from an RTF file. After conversion, you will probably be able to get the text in attributed strings or even HTML if it works correctly with the generated output.

Scroll to Top