【问题标题】:can't send an email with MFMailComposeViewController无法使用 MFMailComposeViewController 发送电子邮件
【发布时间】:2016-12-19 17:13:04
【问题描述】:

我无法从我的应用程序内部在 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];
}

【问题讨论】:

    标签: objective-c mfmailcomposeviewcontroller


    【解决方案1】:
    - (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");
    }
    
    }
    

    【讨论】:

    • 您是否只是复制了我的代码并将其作为答案提交?
    猜你喜欢
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 2011-01-06
    • 1970-01-01
    • 1970-01-01
    • 2015-06-11
    • 2015-11-19
    • 2010-12-04
    相关资源
    最近更新 更多