Ios7 使用MFMailComposeViewController在iOS 7中发送电子邮件时出现问题

Ios7 使用MFMailComposeViewController在iOS 7中发送电子邮件时出现问题,ios7,mfmailcomposeviewcontroller,mfmailcomposer,Ios7,Mfmailcomposeviewcontroller,Mfmailcomposer,我有一个非常简单的应用程序来测试发送电子邮件,但电子邮件从未到达。我在应用程序中包含了MessageUI框架,并实现了MFMailComposeViewController Delegate。应用程序中的两种方法如下: - (IBAction)showEmail:(id)sender { // Email Subject NSString *emailTitle = @"Test Email"; // Email Content NSString *message

我有一个非常简单的应用程序来测试发送电子邮件,但电子邮件从未到达。我在应用程序中包含了MessageUI框架,并实现了MFMailComposeViewController Delegate。应用程序中的两种方法如下:

- (IBAction)showEmail:(id)sender
{
    // Email Subject
    NSString *emailTitle = @"Test Email";
    // Email Content
    NSString *messageBody = @"iOS programming is so fun!";
    // To address
    NSArray *toRecipents = [NSArray arrayWithObject:@"email@address.com"];

    MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
    mc.mailComposeDelegate = self;
   [mc setSubject:emailTitle];
   [mc setMessageBody:messageBody isHTML:NO];
   [mc setToRecipients:toRecipents];

   // Present mail view controller on screen
   [self presentViewController:mc animated:YES completion:NULL];
}

和委托方法:

- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail cancelled");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail sent");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail sent failure: %@", [error localizedDescription]);
            break;
        default:
            break;
    }

    // Close the Mail Interface
    [self dismissViewControllerAnimated:YES completion:NULL];
}
当我按下应用程序中的电子邮件按钮时,第一种方法工作正常,当我单击显示的发送按钮时,“邮件已发送”消息将显示在日志中。电子邮件根本就没有收到

一切似乎都像广告宣传的那样工作,除了电子邮件从未到达目的地

我是在iPad上运行的,不是在模拟器上,我有一个良好的网络连接


我遗漏了什么?

显然这是iPad本身的电子邮件配置问题。重新启动设备后,上述代码可以正常工作。我绝对讨厌这种问题。

使用
canSendMail
方法。 使用以下代码检查是否设置了设备邮件配置。否则你的应用程序将崩溃

if ([MFMailComposeViewController canSendMail])
{
    // Create and show the MailComposeViewController
}
else
{
    // Show No mail account set up on device.
}