MFMail class provides a standard interface for managing, editing, and sending an email message. Use this view controller to display a standard email interface inside your app. Before presenting the interface, populate the fields with initial values for the subject, email recipients, body text, and attachments of the email. After presenting the interface, the user can edit your initial values before sending the email.
- iOS 3.0+
The composition interface does not guarantee the delivery of your email message; it only lets you construct the initial message and present it for user approval. The user may opt to cancel the composition interface, in which case the message and its contents are discarded. If the user opts to send the message, the message is queued in the user’s Mail app outbox. The Mail app is ultimately responsible for sending the message.
An alternate way to compose emails is to create and open a URL that uses the
mailto scheme. URLs of that type are directed to the built-in Mail app, which uses your URL to configure a message. For information about the structure of
mailto URLs, see Apple URL Scheme Reference.
Checking the Availability of the Composition Interface
Before presenting the mail compose view controller, always call the the
can method to see if the current device is configured to send email. If the user’s device is not set up for the delivery of email, you can notify the user or simply disable the email dispatch features in your application. You should not attempt to use this interface if the
can method returns
Configuring and Displaying the Composition Interface
After verifying that mail services are available, you can create and configure the mail composition view controller and then present it like you would any other view controller. Use the methods of this class to specify the subject, recipients, and message body of the email, including any attachments you want to send with the message. Listing 2 shows how to configure the composition interface and present it modally. Always assign a delegate to the
The mail compose view controller is not dismissed automatically. When the user taps the buttons to send the email or cancel the interface, the mail compose view controller calls the
The user can delete a queued message before it is sent. Although the view controller reports the success or failure of the operation to its delegate, this class does not provide a way for you to verify whether the email was actually sent.
For more information on how to present and dismiss view controllers, see View Controller Programming Guide for iOS.