MFMailComposeViewController *mailC=[[MFMailComposeViewControlleralloc] init];
if ([MFMailComposeViewControllercanSendMail]) {
mailC.mailComposeDelegate=self;
[mailC setSubject:@"I have a something to do"];
NSString *emailBody = @"this is text email";
[mailC setMessageBody:emailBody isHTML:YES];
[selfpresentModalViewController:mailC animated:YES];
}
[mailC release];
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult :(MFMailComposeResult)result error:(NSError*)error {
NSString *msg;
switch (result)
{
case MFMailComposeResultCancelled:
msg = @"邮件发送取消";
break;
case MFMailComposeResultSaved:
msg = @"邮件保存成功";
// [self alertWithTitle:nil msg:msg];
break;
case MFMailComposeResultSent:
msg = @"邮件发送成功";
//[self alertWithTitle:nil msg:msg];
break;
case MFMailComposeResultFailed:
msg = @"邮件发送失败";
//[self alertWithTitle:nil msg:msg];
break;
default:
break;
}
UIAlertView *al = [[UIAlertViewalloc] initWithTitle:msg message:@""delegate:nilcancelButtonTitle:@"OK"otherButtonTitles:nil];
[al show];
[al release];
// NSLog(@"msg=%@",msg);
[selfdismissModalViewControllerAnimated:YES];
}
要添加messageui.framework!需要包含#import <MessageUI/MessageUI.h>