无法使用MFMailComposeViewController发送电子邮件

时间:2016-12-19 17:13:04

标签: objective-c mfmailcomposeviewcontroller

我在我的应用内部发送MFMailComposeViewController中的电子邮件时遇到问题。我收到一条发送电子邮件的日志消息,但它从未发送到我的帐户。我必须转到本机邮件应用程序并从发件箱发送它。没有错误告诉我即使在本机应用程序内也失败了。我错过了隐私设置或其他什么?这原本很好。我在iOS 10更新后遇到了这个问题。

-(void)sendEmail:(NSString*)email order:(NSMutableArray *)orderA{
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
if ([MFMailComposeViewController canSendMail])
{

    mail.mailComposeDelegate = self;
    [mail setSubject:[NSString stringWithFormat:@"Order #%@ order", storeNum]];
    [mail setMessageBody:[orderA description] isHTML:NO];
    [mail setToRecipients:@[email]];
    [self presentViewController:mail animated:YES completion:nil];
}
else
{
    NSLog(@"This device cannot send email");
}
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result) {
    case MFMailComposeResultSent:
        NSLog(@"You sent the email.");
        break;
    case MFMailComposeResultSaved:
        NSLog(@"You saved a draft of this email");
        break;
    case MFMailComposeResultCancelled:
        NSLog(@"You cancelled sending this email.");
        break;
    case MFMailComposeResultFailed:
        NSLog(@"Mail failed:  An error occurred when trying to compose this email");
        break;
    default:
        NSLog(@"An error occurred when trying to compose this email");
        break;
}

[self dismissViewControllerAnimated:YES completion:nil];
}

1 个答案:

答案 0 :(得分:0)

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result) {
    case MFMailComposeResultSent:
        NSLog(@"You sent the email.");
        break;
    case MFMailComposeResultSaved:
        NSLog(@"You saved a draft of this email");
        break;
    case MFMailComposeResultCancelled:
        NSLog(@"You cancelled sending this email.");
        break;
    case MFMailComposeResultFailed:
        NSLog(@"Mail failed:  An error occurred when trying to compose this email");
        break;
    default:
        NSLog(@"An error occurred when trying to compose this email");
        break;
}

[self dismissViewControllerAnimated:YES completion:NULL];
}


-(IBAction)mailClick:(id)sender{

if ([MFMailComposeViewController canSendMail])
{
    MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
    mail.mailComposeDelegate = self;
    [mail setSubject:@"Message from XYZ"];
    // [mail setMessageBody:@"Here is some main text in the email!" isHTML:NO];
    [mail setToRecipients:@[@"yourMail@gmail.com"]];

    [self presentViewController:mail animated:YES completion:NULL];
}
else
{

    NSLog(@"This device cannot send email");
}

}