2012-11-10 53 views
1

是否允許將本地存儲的HTML頁面附加到從我的iOS應用程序發送的電子郵件?iOS - 將本地HTML頁面附加到電子郵件

什麼是正確的mimeType?

編輯

這是我的代碼不能正常工作,請POIT在哪裏是防止本地HTML文件的附件問題。

-(IBAction)share:(id)sender{ 


NSString *btn_title = [sender titleForState:(UIControlStateNormal)]; 

if ([btn_title isEqualToString: @"fb"]) { 


}else if ([btn_title isEqualToString: @"tw"]){ 


}else if ([btn_title isEqualToString: @"email"]){ 

    if ([MFMailComposeViewController canSendMail]) 
    { 
     MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init]; 
     mailer.mailComposeDelegate = self; 
     [mailer setSubject:@""]; 
     NSArray *toRecipients = [NSArray arrayWithObjects:@"", nil]; 
     [mailer setToRecipients:toRecipients]; 

     NSString *emailBody = @""; 

     NSError * error = nil; 
     NSData *htmlData = [NSData dataWithContentsOfFile:@"/hamla.html" options: NSMappedRead error: &error]; 

     [mailer addAttachmentData:htmlData mimeType:@"text/html" fileName:@"hamla"]; 

     [mailer setMessageBody:emailBody isHTML:NO]; 
     [self presentModalViewController:mailer animated:YES]; 
    } 
    else 
    { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure" 
                 message:@"Your device doesn't support the composer sheet" 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles: nil]; 
     [alert show]; 
    } 
} 

}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{ 
    switch (result) 
    { 
     case MFMailComposeResultCancelled: 
      NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued."); 
      break; 
     case MFMailComposeResultSaved: 
      NSLog(@"Mail saved: you saved the email message in the drafts folder."); 
      break; 
     case MFMailComposeResultSent: 
      NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send."); 
      break; 
     case MFMailComposeResultFailed: 
      NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error."); 
      break; 
     default: 
      NSLog(@"Mail not sent."); 
      break; 
    } 
    // Remove the mail view 
    [self dismissModalViewControllerAnimated:YES]; 
} 

回答

0

@Shymaa奧斯曼MIME類型ü[R使用的correct.Just需要知道具有u檢查U是否正確 - [R定位烏爾HTML和獲得的NSData不爲空..? 如果沒有,請在附加郵件之前嘗試使用此代碼。

NSData NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"hamla" ofType:@"html"]; 

NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile]; 
0

它適用於當我isMessageBody與isHTML = YES,加上添加文本附件。

NSData *stringData = [textBody dataUsingEncoding:NSUTF8StringEncoding]; 
[mailer addAttachmentData:stringData 
       mimeType:@"text/plain" 
       fileName:@"text_file"]; 
相關問題