3

I have a very simple app to test sending email, but the email never arrives. I have included the MessageUI framework in the app, and implemented the MFMailComposeViewControllerDelegate as well. The two methods in the app are as follows:

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

}

and the delegate method:

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

When I press the email button in my app the first method works perfectly and when I click the send button that is presented, the "Mail Sent" message appears in the log. The email simply never arrives.

Everything seems to work as advertised, with the exception of the email never arriving at its destination.

I am running this on the iPad not in the simulator, and I have a good network connection.

What am I missing?

4

2 回答 2

1

显然这是 iPad 本身的电子邮件配置问题。重新启动设备后,上面的代码可以完美运行。我绝对讨厌这种问题。

于 2014-03-30T16:59:55.717 回答
0

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

if ([MFMailComposeViewController canSendMail])
{
    // Create and show the MailComposeViewController
}
else
{
    // Show No mail account set up on device.
}
于 2014-08-25T14:13:17.007 回答