id | title | brief | sdk | |||||
---|---|---|---|---|---|---|---|---|
F2D2C19F-BBF3-541F-40CA-33E41E42B3D3 |
Send an Email |
This recipe shows how to send an email using the MFMailComposeViewController. |
|
To send an email using the MFMailComposeViewController
follow these
steps.
- Create a class variable for an MFMailComposeViewController.
MFMailComposeViewController mailController;
- 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
}
- 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.DismissViewController (true, null);
};
- Present the
MFMailComposeViewController
.
this.PresentViewController (mailController, true, null);
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