Get list of "From" in MFMailCompose

40 views Asked by At

Ideally, I would like to be able to set the "From" field of the MFMailComposeViewController, but it appears this is not possible (to my knowledge) from my digging in through apple documentation (like here) and forums (like here).

So, if not possible to set the field, I would like to at least be able read the available addresses and prompt the user with a popup when the MFMailComposeViewController is accessed and can send mail. As such:

if( MFMailComposeViewController.canSendMail() ) {
        let alertTitle = "Mail Accounts Setup"
        let alertMessage = "The following accounts are set up in Mail: \(accountsAvailable)"
        let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
        alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { action in
            switch action.style{
            case .default:
                print("default")

            case .cancel:
                print("cancel")

            case .destructive:
                print("destructive")
            }
        }))
        self.present(alert, animated: true, completion: nil)

        //... rest of mailController code
}

The piece of this that I am trying to figure out is how to read the available addresses to put in place of the accountsAvailable variable above.

Additionally Considerations

What I would need here is to be able to read the accounts that have been set up to work with MFMailComposeViewController. I presume that the .canSendMail() may check that at least one email available for the "from" field in order for the function to return true, so I was thinking that it may possible to override that function? Alternatively, the MFMailComposeViewController loads the "from" field into the resulting view when the user has more than one account available, so I am hoping there may be a way to access this.

Any help would be enormously appreciated! Thanks in advance.

0

There are 0 answers