只需将委托添加MFMessageComposeViewControllerDelegate
到 .h 文件,然后在您想发送电子邮件时使用此代码,并MessageUI.framework
在项目中添加框架
-(IBAction)forgetpassword:(id)sender
{
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
NSString *mailBody = @"your Message";
[mailComposeViewController setMessageBody:mailBody isHTML:NO];
mailComposeViewController.mailComposeDelegate = self;
[self presentViewController:mailComposeViewController animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"e-Mail Sending Alert"
message:@"You can't send a mail"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[alert release];
}
}
这个波纹管方法是委托方法MFMessageComposeViewControllerDelegate
#pragma mark - MFMessage Delegate
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
if (result == MFMailComposeResultSent)
{
NSLog(@"\n\n Email Sent");
}
[self dismissViewControllerAnimated:YES completion:nil];
}
您还可以使用SKPSMTPmessage网络服务发送电子邮件
我希望这可以帮助你...