MFMailComposeViewController error [MC] Filtering mail sheet accounts for bundle ID
Asked Answered
F

7

10

I do the standard functionality of sending messages with MFMailComposeViewController.

My code:

if MFMailComposeViewController.canSendMail()
{
    let mail = MFMailComposeViewController()
    mail.mailComposeDelegate = self
    mail.setToRecipients(["[email protected]"])
    mail.setSubject("Subject")
    mail.setMessageBody("Some Text", isHTML: false)
    self.presentViewController(mail, animated: true, completion: nil)
}

Controller do not open and I see a message in the console that have never seen.

[MC] Filtering mail sheet accounts for bundle ID: [My Bundle ID], source account management: 1

[MC] Result: NO

Help please.

Famulus answered 15/11, 2016 at 11:28 Comment(4)
I have the exact same problem! I've tried in the simulator, and it works in ios 9 but not in ios 10.Inflated
got solution for this issue??Autosuggestion
still looking for a solution :(Jam
Seven answers, none of them correct.Polymath
P
2

If a mail account has been set at the device where you try to test your application there is no problem. Please create a mail account.

Propound answered 12/10, 2017 at 11:39 Comment(2)
can you please elaborate more ?Emalee
no, I tested on a physical device with my mail account signed in, and get the same errorLaevogyrate
D
1

For Swift 3.0.1 - 4.2 Compatible

if MFMailComposeViewController.canSendMail()
{
    let mail = MFMailComposeViewController()
    mail.mailComposeDelegate = self
    mail.setToRecipients(["[email protected]"])
    mail.setSubject("Subject")
    mail.setMessageBody("Some Text", isHTML: false)
    self.present(mail, animated: true, completion: nil)
}

I had the same error though it works perfectly on my device with iOS 10.1.1. I had a similar problem and found that the Mail Composer would only work on iOS 9 in the simulator, there is some sort of bug with iOS 10 and running Mail Composer on the simulator with my current knowledge.

Update I have also tested this with a device with iOS 11.4 and got the same results.

Tried these calls to open mail on the simulator and they did not work. Though work they work fine on a real device.

UIApplication.shared.keyWindow?.rootViewController?.present(mail, animated: true)
self.navigationController?.present(mail, animated: true, completion: nil)
Donor answered 7/12, 2016 at 22:20 Comment(0)
P
0

Had the same problem. It was connected with presenter.

You need to present MFMailComposeViewController from UINavigationController. Try this:

self.navigationController.presentViewController(mail, animated: true, completion: nil)

It solved my problem.

Periderm answered 3/2, 2017 at 12:24 Comment(0)
F
0

If you check the value of MFMailComposeViewController.canSendMail(), you will see that it is false. So that the code inside your if statement would not get executed. And to return true, you need to enable one email on your mobile phone.

Finegan answered 25/7, 2018 at 3:2 Comment(0)
G
0

You need to Login in 'Mail' App in order to present the Mail Composer.

Grapple answered 16/4, 2019 at 1:5 Comment(0)
G
-1

For me this answer solved the problem. I had the same issue on a real device with active mail accounts and changed the presenting view controller to

        let mailComposeViewController = MFMailComposeViewController()
        mailComposeViewController.mailComposeDelegate = self
        mailComposeViewController.setToRecipients([address])
        mailComposeViewController.setMessageBody(message, isHTML: false)
        mailComposeViewController.setSubject(subject)


        UIApplication.shared.keyWindow?.rootViewController?.present(mailComposeViewController, animated: true)
Gluten answered 18/9, 2018 at 15:44 Comment(0)
J
-1
@IBAction func gmailButton(_ sender: UIButton){
    self.popUp()
}

func popUp(){
    guard MFMailComposeViewController.canSendMail() else {
        return
    }

    let composer = MFMailComposeViewController()
    composer.mailComposeDelegate = self
    composer.setToRecipients(["[email protected]"])
    composer.setSubject("succes")
    composer.setMessageBody("succes sent", isHTML: false)
    present(composer, animated: true)
}

First you have to log in to Gmail, after that this program can be used. don't forget use real device to try this

Jobye answered 11/3, 2019 at 9:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.