can't send an email with MFMailComposeViewController

623 views Asked by At

I'm having trouble sending an email in MFMailComposeViewController from inside my app. I get a log message that the email was sent, but it never sends to my account. I have to go to the native Mail app and send it from the outbox. There is no error telling me way it failed even inside the native app. Am I missing a privacy setting or something? This originally worked fine. I'm having the issue after iOS 10 update.

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

There are 1 answers

1
Dishant Rajput On
- (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:@[@"[email protected]"]];

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

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

}