如何在iphone SDK中发送电子邮件?

时间:2009-10-03 09:32:22

标签: iphone

如何在iphone SDK中发送电子邮件?任何从iphone获取电子邮件地址的示例教程 也?

1 个答案:

答案 0 :(得分:17)

您应该使用隐藏在MessageUI框架中的MFMailComposeViewController类和MFMailComposeViewControllerDelegate协议。

首先发送消息:

MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"My Subject"];
[controller setMessageBody:@"Hello there." isHTML:NO]; 
[self presentModalViewController:controller animated:YES];
[controller release];

然后用户完成工作并及时获得委托回调:

- (void)mailComposeController:(MFMailComposeViewController*)controller  
          didFinishWithResult:(MFMailComposeResult)result 
                        error:(NSError*)error;
{
  if (result == MFMailComposeResultSent) {
    NSLog(@"It's away!");
  }
  [self dismissModalViewControllerAnimated:YES];
}