Sample code for 30+ languages & platforms
Objective-C Requires Chilkat v11.0.0+

Read an attached email

See more Email Object Examples

Open forward-as-attachment.eml from the forwarding example. Read the cover note’s subject, then open each attached message and inspect its own headers and attachment count. This works even when the outer message has no ordinary files.

Chilkat Objective-C Downloads

Objective-C
#import <CkoEmail.h>

BOOL success = NO;

//  Assumes Chilkat is unlocked. See Global Unlock Sample.

CkoEmail *wrapper = [[CkoEmail alloc] init];
success = [wrapper LoadEml: @"forward-as-attachment.eml"];
if (success != YES) {
    NSLog(@"%@",wrapper.LastErrorText);
    return;
}

NSLog(@"%@%@",@"Cover note: ",wrapper.Subject);
if ([wrapper.NumAttachedMessages intValue] == 0) {
    NSLog(@"%@",@"No attached messages.");
    return;
}

CkoEmail *nested = [[CkoEmail alloc] init];
int i = 0;
while ((i < [wrapper.NumAttachedMessages intValue])) {
    success = [wrapper GetAttachedEmail: [NSNumber numberWithInt: i] email: nested];
    if (success != YES) {
        NSLog(@"%@",wrapper.LastErrorText);
        return;
    }

    NSLog(@"%@%@",@"Original author: ",nested.From);
    NSLog(@"%@%@",@"Original subject: ",nested.Subject);
    NSLog(@"%@%d",@"Files on the original: ",[nested.NumAttachments intValue]);
    i = i + 1;
}