Mail Message
The MFMailComposeViewController class, a UINavigationController, allows the user to edit a mail message. The user can attempt to send the message there and then, or can cancel but save a draft, or can cancel completely. Before using this class to present a view, call canSendMail; if the result is NO, go no further, as a negative result means that the device is not configured for sending mail. A positive result does not mean that the device is connected to the network and can send mail right now, only that sending mail is generally possible with this device; actually sending the mail (or storing it as a draft) will be up to the device’s internal processes.
To use MFMailComposeViewController, instantiate it, provide a mailComposeDelegate (not delegate), and configure the message to any desired extent. The user can later alter your preset configurations, at which time the message details will be out of your hands. Configuration methods are:
-
setSubject: -
setToRecipients: -
setCcRecipients: -
setBccRecipients: -
setMessageBody:isHTML: -
addAttachmentData:mimeType:fileName:
Typically, you’ll show the MFMailComposeViewController as a presented view controller. This approach works equally well on the iPad (use UIModalPresentationFormSheet if a full-screen presentation feels too overwhelming).
The delegate (MFMailComposeViewControllerDelegate) will receive the message mailComposeController:didFinishWithResult:error: describing the user’s final action, which might be any of these: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access