The Message Framework
The message framework, consisting of the
single
NSMailDelivery
class, provides the functionality needed
to send email messages from within an application. The
NSMailDelivery
class defines three methods:
hasDeliveryClassBeenConfigured
deliverMessage:headers:format:protocol
:deliverMessage:subject:to
:
The first method,
hasDeliveryClassBeenConfigured
, returns a BOOL
value that indicates whether the operating system is configured to
send messages. To make sure that any attempt to send a message is not
in vain, invoke this method before sending a message, and handle
appropriately if NO
is returned. Message sending
is enabled by configuring a default email account in the Internet
System Preferences pane.
The second method,
deliverMessage:headers:format:protocol
:
, delivers a message whose text is
contained in an NSAttributedString
. The standard
message headers, such as “To”,
“From”, and
“Subject”, are passed in the
headers
: parameter as a dictionary. In this
dictionary, the key is the header name. For example, the
recipient’s email address would be an
NSString
value in the dictionary for the key
@"To
“. Example 8-6 shows how to
use this dictionary and the mail delivery methods.
The third parameter specifies the message’s format,
which can be one of two constants:
NSASCIIMailFormat
or
NSMIMEMailFormat
. If
NSASCIIMailFormat
is specified as the format, then
the attributed string is stripped of any rich text formatting
information. NSMIMEMailFormat
, on the other hand, ...
Get Cocoa in a Nutshell 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.