2013-04-17 42 views
2

我在UIWebView中顯示了一個html文件。我需要將我的當前頁面作爲附件和附件郵寄給html文件。我的代碼,如何在iPhone sdk中將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 *[email protected]""; 
switch (result) { 
    case MFMailComposeResultCancelled: 
     NSLog(@"Mail send canceled."); 
     [email protected]"\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."); 
     [email protected]"Mail saved"; 
     /* 
     Execute your code for email saved event here ... 
     */ 
     break; 
    case MFMailComposeResultSent: 
     NSLog(@"Mail sent."); 
     [email protected]"Mail sent"; 
     /* 
     Execute your code for email sent event here ... 
     */ 
     break; 
    case MFMailComposeResultFailed: 
     [email protected]"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文件?提前致謝。

回答

0

您必須將mimeType設置爲mimeType:@"text/html"。我認爲沒有其他方式發送特定頁面(當前頁面)作爲附件在MFMailComposer ..看到這link設置mimetype

相關問題