Chapter 33. Mail

Your app can present an interface allowing the user to edit and send a mail message or an SMS message. Two view controller classes are provided by the Message UI framework; your app will link to MessageUI.framework and import <MessageUI/MessageUI.h>. The classes are:

MFMailComposeViewController
Allows composition and sending of a mail message.
MFMessageComposeViewController
Allows composition and sending of an SMS message.

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:

Get Programming iOS 5, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.