2009-10-03 69 views
7

如何在iphone SDK中發送電子郵件?任何示例教程也可以從iphone 獲取電子郵件地址?如何在iphone SDK中發送電子郵件?

+0

可能的複製http://stackoverflow.com/questions/ 310946/how-can-i-send-mail-from-iphone-application – luvieere 2009-10-03 09:39:05

+0

重複是的,但問題是舊的,只有iPhone OS 2.0的答案。 – PeyloW 2009-10-03 10:32:14

+0

在提問之前嘗試使用搜索。如果你投票已經發布了正確的答案,它會有很大的幫助。 – Jordan 2009-10-03 11:25:49

回答

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]; 
}