[英]How to attach a HTML page to my mail composer in iPhone sdk?
我在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文件發送? 提前致謝。
您必須將mimeType設置為mimeType:@"text/html"
。 我認為沒有其他方法可以將特定頁面(當前頁面)作為附件發送到MFMailComposer中。請參閱此鏈接來設置mimetype
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.