This recipe shows how to send an email using the MFMailComposeViewController.
Recipe
To send an email using the MFMailComposeViewController follow these steps.
- Create a class variable for an MFMailComposeViewController.
MFMailComposeViewController _mailController;
- Instantiate an MFMailComposeViewController instance.
_mailController = new MFMailComposeViewController ();
- Set the recipients, subject and message body.
_mailController.SetToRecipients (new string[]{"john@doe.com"}); _mailController.SetSubject ("mail test"); _mailController.SetMessageBody ("this is a test", false);
- Handle the Finished event.
_mailController.Finished += ( object s, MFComposeResultEventArgs args) => { Console.WriteLine (args.Result.ToString ()); args.Controller.DismissModalViewControllerAnimated (true); };
- Present the MFMailComposeViewController.
this.PresentModalViewController (_mailController, true);
Additional Information
The MFMailComposeViewController class has built-in support for sending emails. You can send emails to multiple recipients by including their addresses in the array passed into SetToRecipients. When the controller is dismissed, the result is available in the Finished event’s MFComposeResultEventArgs.Result, which is an MFMailComposeResult enumeration.
