Objective-C
Objective-C
Get and Set the Email Body
See more Email Object Examples
Demonstrates the Chilkat Email.Body property. When you set Body, Chilkat inspects the content and decides whether it should be treated as HTML or plain-text. When you read Body, an email that contains both plain-text and HTML alternatives returns the HTML body — use GetHtmlBody or GetPlainTextBody to retrieve a specific representation. This example sets a plain-text body and reads it back.
Background: A single email often carries two versions of the same message — a plain-text body and an HTML body — bundled together in a
multipart/alternative MIME structure. The receiving mail client picks whichever version it prefers to display. Because of this, "the body" is ambiguous: the Body property favors the HTML version when both are present, which is why Chilkat also provides GetHtmlBody, GetPlainTextBody, HasHtmlBody, and HasPlainTextBody for precise control.Chilkat Objective-C Downloads
#import <CkoEmail.h>
#import <NSString.h>
// Demonstrates getting and setting the Email.Body property.
// When setting Body, Chilkat inspects the content to decide whether it is
// HTML or plain-text. When reading, an email that has both plain-text and
// HTML alternatives returns the HTML body.
CkoEmail *email = [[CkoEmail alloc] init];
// Set the body.
email.Body = @"This is the plain-text body of the email.";
// Read the Body property back.
NSString *bodyText = email.Body;
NSLog(@"%@%@",@"Body = ",bodyText);