0

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.

Community
  • 1
  • 1
Rbar
  • 3,740
  • 9
  • 39
  • 69
  • Why are you trying to set the "from" field? That's the user's job if they have more than one account. – rmaddy Dec 14 '16 at 17:45
  • Hey @rmaddy, thanks for the comment. If the user uses a mail client (say the GMail app) instead of Mail, then their preferred email may not be set up in Mail at all or may not be the default email in Mail. Therefore, the user may unknowingly or unintentionally send the email from the app from an account they don't use (which happened for a user of ours) and result in them not receiving a response to an account they check. – Rbar Dec 14 '16 at 18:09
  • If the account isn't set up for the Mail app, then the account can't be used by `MFMailComposeViewController`. – rmaddy Dec 14 '16 at 18:17
  • @rmaddy, I agree with you. That is why I want to show the user which accounts are available. If the account they would like is not listed, then they will know to go into add the account in settings (or we will tell them to) – Rbar Dec 14 '16 at 18:41
  • There is no API to get the list of mail accounts the user has setup. What you want can't be done. – rmaddy Dec 14 '16 at 19:53

0 Answers0