O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required