Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Latest commit

 

History

History

send_an_email

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
id title brief sdk
F2D2C19F-BBF3-541F-40CA-33E41E42B3D3
Send an Email
This recipe shows how to send an email using the MFMailComposeViewController.

Recipe

To send an email using the MFMailComposeViewController follow these steps.

  1. Create a class variable for an MFMailComposeViewController.
MFMailComposeViewController mailController;
  1. Verify that the device is capable of sending mail - ensure you wrap all mail functionality inside the following CanSendMail check:
if (MFMailComposeViewController.CanSendMail) {
  // do mail operations here
}
  1. Instantiate an MFMailComposeViewController instance.
mailController = new MFMailComposeViewController ();
  1. 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);
  1. Handle the Finished event.
mailController.Finished += ( object s, MFComposeResultEventArgs args) => {
  Console.WriteLine (args.Result.ToString ());
  args.Controller.DismissViewController (true, null);
};
  1. Present the MFMailComposeViewController.
this.PresentViewController (mailController, true, null);

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.

It is highly recommended that you test mail operations on real devices and not rely on results in the iOS Simulator