Take the 2-minute tour ×

I am working on a mail application. I have a table view in a view, I need to load a mail page when I click on a button in the same view. I have implemented this using MFMailComposeViewController.

The mail view loaded, but I need to send the content of the table view as body/ attach of the body of mail, instead of icon image.

    MFMailComposeViewController *mailpage = [[MFMailComposeViewController alloc] init];
    mailpage.mailComposeDelegate = self;
    [mailpage setSubject:@"summary of chronology"];

    // Set up recipients
    NSArray *ccRecipients = [NSArray arrayWithObjects:@"",nil]; 
    NSArray *bccRecipients = [NSArray arrayWithObject:@""]; 

    [mailpage setToRecipients:toRecipients];
    [mailpage setCcRecipients:ccRecipients];    
    [mailpage setBccRecipients:bccRecipients];

    //Attach an image to the email
      NSString *path = [[NSBundle mainBundle] pathForResource:@"iCon" ofType:@"png"];
      NSData *myData = [NSData dataWithContentsOfFile:path];
     [mailpage addAttachmentData:myData mimeType:@"image/png" fileName:@"iCon"];

    // Fill out the email body text
    NSString *emailBody = @"";
    [mailpage setMessageBody:emailBody isHTML:NO];

    [self presentModalViewController:mailpage animated:YES];
    //[self.navigationController pushViewController:mailpage animated:YES];
    [mailpage release];
share|improve this question

2 Answers 2

up vote 4 down vote accepted

Add to your displayComposerMethod this piece of code:

NSString *emailBody = [self generateHTMLBody];
[mailpage setMessageBody:emailBody isHTML:YES];

and method like this:

//assume that you have objects in NSArray* dataArray
- (NSString *)generateHTMLBody {
    NSString *res = @"<HTML><body><table>\n";

    for (int i=0; i < dataArray.count; i++) {
        NSString *tmp = (NSString *)[dataArray objectAtIndex:i];
        res = res = [res stringByAppendingString:@"<tr><td>"];
        res = res = [res stringByAppendingString:tmp];
        res = res = [res stringByAppendingString:@"</td></tr>\n"]; //fix in this line
    res = [res stringByAppendingString:@"</table></body></html>\n"];
    return res;
// I didn't test this method.

This is of course only an example, and method generateHTMLBody can and should be more sophisticated.

share|improve this answer
thank u very much Tomasz.. its working. –  iOS dev Jan 30 '12 at 10:24
I'm glad I could help you. I fixed small bug in commented line (there was incorrect sequence of tags). –  Tomasz Wojtkowiak Jan 30 '12 at 11:06

This code helps to reload the parent page by making any changes(if there)#refresh

header("location:crud_admin.php"); echo 'parent.window.location.reload(true);';

share|improve this answer
How does this answer the question? –  Jonathan Drapeau Jan 16 at 13:27

Your Answer


