Forum Xamarin.iOS

Need help to handle e-mail, when device's email account not setup on iOS

Whitchurch.6690Whitchurch.6690 USMember ✭✭
edited September 2016 in Xamarin.iOS

I have written some code, to open the the email app on the phone(device) and auto populate, the e-mail with the passed in parameter.

  • Everything works fine, if I have setup the e-mail account as expected.
  • If I do not have the e-mail account setup the app crashes.

  • I have written the following code hoping that a return at CanSendMail would prevent the crash, but it is not helping:

System.Diagnostics.Debug.WriteLine("Unable to send mail"); // Still crashes at the return.
return ;
var _mailController = new MFMailComposeViewController();

                _mailController.SetToRecipients(new[] { "[email protected]" });
                _mailController.SetSubject("E-mail Subject");
                _mailController.SetMessageBody("Blah blah blah", false);

                // Handle the action to take when the user completes sending the email
                _mailController.Finished += (object s, MFComposeResultEventArgs args) => {
                    args.Controller.DismissViewController(true, null);

                UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(_mailController, true, null);


Best Answer


Sign In or Register to comment.