如何在iPhone sdk中将HTML页面附加到我的邮件编辑器?

时间:2013-04-17 06:48:29

标签: iphone html ios mfmailcomposer

我在UIWebView中显示了一个html文件。我需要将当前页面作为附件和附件邮寄为html文件。我的代码,

-(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];
}

使用此代码可以将带有指定html文件(整个html文件)的邮件作为附件发送。我正在接收邮件作为文本文件。现在我怎么能只发送当前页面和附件的邮件作为html文件?提前谢谢。

1 个答案:

答案 0 :(得分:0)

您必须将mimeType设置为mimeType:@"text/html"。我认为没有其他方法可以在MFMailComposer中将特定页面(当前页面)作为附件发送..请参阅此link以设置mimetype