2013-07-05 56 views
1

我必须发送HTML文本作为附件与PDF扩展名。发送html文本作为PDF格式的ios附件邮件

代码:

MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init]; 
    mailViewController.mailComposeDelegate = self; 
    NSArray *toReceipents =[NSArray arrayWithObjects:@"", nil]; 
    [mailViewController setToRecipients:toReceipents]; 
    [mailViewController setSubject:strMailMessage]; 
    NSLog(@"Mail Message:%@ %@",strMailMessage,appDelegate.strShareText); 
    NSData* data = [appDelegate.strShareText dataUsingEncoding:NSUTF8StringEncoding]; 
    [mailViewController setMessageBody:appDelegate.strShareText isHTML:YES]; 
    [mailViewController addAttachmentData:data mimeType:@"application/pdf" fileName:@"Medication file.pdf"]; 
    [self presentModalViewController:mailViewController animated:YES]; 
    [mailViewController release]; 

注:当我下载的pdf文件我得到相同text.but我想显示PDF文档

回答

0

良好的代码但HTML表格格式的文本试试这个;):

- (IBAction)mailCompose:(id)sender { 

     MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init]; 
     mail.mailComposeDelegate = self; 

     [mail setSubject:@"Hello World!"]; 
     NSArray *toRecipients = [NSArray arrayWithObjects:@"e-mail here or leve empty", nil]; 

     [mail setToRecipients:toRecipients]; 
     NSString *emailBody = @"Body message App</b><br /><a href='https://itunes.apple.com/it/app/yourApp/id'>Download Free on AppStore!</a>"; 

     NSString *documentsDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; 
     NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"myVoice.caf"]; 
     NSData *myData = [NSData dataWithContentsOfFile:filePath]; 
     [mail addAttachmentData:myData mimeType:documentsDirectory fileName:@"myVoice.caf"]; 


     [mail setMessageBody:emailBody isHTML:YES]; 
     mail.modalPresentationStyle = UIModalPresentationPageSheet; 
     [self presentViewController:mail animated:YES completion:nil]; 

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

    switch (result) { 
     case MFMailComposeResultCancelled: 
      NSLog(@"Cancelled"); 
      break; 
     case MFMailComposeResultSaved: 
      NSLog(@"Saved"); 
      break; 
     case MFMailComposeResultFailed: 
      NSLog(@"Faild"); 
      break; 
     case MFMailComposeResultSent: 
      NSLog(@"Sent"); 
      break; 
     default: 
      NSLog(@"Default"); 
      break; 
    } 

    [self dismissViewControllerAnimated:YES completion:nil]; 

} 

Enjy希望这可以帮助你

相关问题