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

Forward an email as an attachment

See more Email Object Examples

Attach the original Email to a new message as a message/rfc822 part. The recipient can open the attached email and read its original headers and body.

Chilkat Objective-C Downloads

Objective-C
#import <CkoEmail.h>

BOOL success = NO;

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

CkoEmail *original = [[CkoEmail alloc] init];
success = [original LoadEml: @"message.eml"];
if (success != YES) {
    NSLog(@"%@",original.LastErrorText);
    return;
}

CkoEmail *email = [[CkoEmail alloc] init];
email.From = @"Sam Lee <sam@example.com>";
success = [email AddTo: @"Alex Rivera" emailAddress: @"alex@example.net"];
if (success != YES) {
    NSLog(@"%@",email.LastErrorText);
    return;
}

email.Subject = @"Forwarded message";
email.Body = @"The original email is attached.";
success = [email AttachEmail: original];
if (success != YES) {
    NSLog(@"%@",email.LastErrorText);
    return;
}

success = [email SaveEml: @"forward-as-attachment.eml"];
if (success != YES) {
    NSLog(@"%@",email.LastErrorText);
    return;
}

NSLog(@"%@",@"Saved forward-as-attachment.eml.");