Objective-C Requires Chilkat v11.0.0+
Objective-C
Read email headers and display the body as text
See more Email Object Examples
Read the sender, recipients, subject, date, and an optional custom header from an EML file. Display the plain-text body when available, or convert HTML to text. Handle messages that contain neither body format.
Chilkat Objective-C Downloads
#import <CkoEmail.h>
#import <NSString.h>
#import <CkoHtmlToText.h>
BOOL success = NO;
// Assumes Chilkat is unlocked. See Global Unlock Sample.
CkoEmail *email = [[CkoEmail alloc] init];
success = [email LoadEml: @"with-attachments.eml"];
if (success != YES) {
NSLog(@"%@",email.LastErrorText);
return;
}
NSLog(@"%@%@",@"From: ",email.From);
NSLog(@"%@%@",@"Subject: ",email.Subject);
NSLog(@"%@%@",@"Date: ",email.EmailDateStr);
int i = 0;
while ((i < [email.NumTo intValue])) {
NSLog(@"%@%@%@%@",@"To: ",[email GetToName: [NSNumber numberWithInt: i]],@" ",[email GetToAddr: [NSNumber numberWithInt: i]]);
i = i + 1;
}
NSString *referenceId = [email GetHeaderField: @"X-Reference-ID"];
if (email.LastMethodSuccess == YES) {
NSLog(@"%@%@",@"Reference: ",referenceId);
}
if ([email HasPlainTextBody] == YES) {
NSLog(@"%@",[email GetPlainTextBody]);
}
else {
if ([email HasHtmlBody] == YES) {
CkoHtmlToText *reader = [[CkoHtmlToText alloc] init];
NSLog(@"%@",[reader ToText: [email GetHtmlBody]]);
}
else {
NSLog(@"%@",@"No text or HTML body.");
}
}