문제

I displayed a html file in a UIWebView. I need to mail my current page as an attachment and attachment as a html file. My code,

-(void)mailClick
{
         NSLog(@"mail");
         if ([MFMailComposeViewController canSendMail])
         {
    //atableView.scrollEnabled=YES;
    //[socailNetworkView removeFromSuperview];
    //  self.navigationItem.title = @"Contents";
    MFMailComposeViewController *mailViewController =           [[MFMailComposeViewController alloc] init];
    mailViewController.mailComposeDelegate = self;
    [mailViewController setSubject:@""];
    NSString *fullPath =[[NSBundle mainBundle] pathForResource:@"first" ofType:@"html"];
    NSData *myData = [NSData dataWithContentsOfFile:fullPath];
    [mailViewController addAttachmentData:myData
                       mimeType:@"text/plain"
                       fileName:@"File_Name"];
    [mailViewController setMessageBody:@"" isHTML:NO];
    NSString *string = [NSString stringWithFormat:@"", nil];


    NSArray *mailArr = [[NSArray alloc] initWithObjects:string,nil];
    [mailViewController setToRecipients:mailArr];
    [self presentModalViewController:mailViewController animated:YES];
    [mailViewController release];

}

else 
    {

    NSLog(@"Device is unable to send email in its current state");

}
  }


- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error;

{

NSLog(@"Mail");
NSString  *str=@"";
switch (result) {
    case MFMailComposeResultCancelled:
        NSLog(@"Mail send canceled.");
        str=@"\nMail sending cancelled";
        msgLabel.text=str;
        [msgLabel setFont:[UIFont fontWithName:@"Arial" size:18]];
        msgLabel.textColor=[UIColor colorWithRed:(54.0/255.0) green:(2.0/255) blue:(1.0/255) alpha:1.0];

        /*
         Execute your code for canceled event here ...
         */
        break;
    case MFMailComposeResultSaved:
        NSLog(@"Mail saved.");
        str=@"Mail saved";
        /*
         Execute your code for email saved event here ...
         */
        break;
    case MFMailComposeResultSent:
        NSLog(@"Mail sent.");
        str=@"Mail sent";
        /*
         Execute your code for email sent event here ...
         */
        break;
    case MFMailComposeResultFailed:
        str=@"Mail not sent";
        NSLog(@"Mail send error: %@.", [error localizedDescription]);
        /*
         Execute your code for email send failed event here ...
         */
        break;
    default:
        break;
}

[self dismissModalViewControllerAnimated:YES];
}

Using this code am able to send mail with the specified html file(whole html file) as an attachment. And am receiving the mail finely as a text document. Now how could i send mail of only my current page and attachment as a html file? Thanks in advance.

도움이 되었습니까?

해결책

You have to set mimeType as mimeType:@"text/html". I think no other way to send particular page(current Page) as attachment in MFMailComposer.. see this link to set mimetype

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top