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

Create an HTML preview with embedded images

See more Email Object Examples

Make an independent copy of with-attachments.eml, remove ordinary file attachments from the copy, and export its HTML with related images as data URLs. The original retains its attachments. Use a sanitized viewer when showing untrusted HTML.

Chilkat Objective-C Downloads

Objective-C
#import <CkoEmail.h>
#import <CkoStringBuilder.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;
}

CkoEmail *preview = [[CkoEmail alloc] init];
success = [email MakeCopy: preview];
if (success != YES) {
    NSLog(@"%@",email.LastErrorText);
    return;
}

//  Keep related items: the HTML still refers to them.
[preview DropAttachments];
NSLog(@"%@%d%@%d",@"Files in original: ",[email.NumAttachments intValue],@"  Files in preview: ",[preview.NumAttachments intValue]);
if ([preview HasHtmlBody] != YES) {
    NSLog(@"%@",@"This message has no HTML preview.");
    return;
}

CkoStringBuilder *html = [[CkoStringBuilder alloc] init];
success = [preview GetHtmlBodySb: YES sb: html];
if (success != YES) {
    NSLog(@"%@",preview.LastErrorText);
    return;
}

success = [html WriteFile: @"preview.html" charset: @"utf-8" emitBom: NO];
if (success != YES) {
    NSLog(@"%@",@"Failed: html.WriteFile.");
    return;
}

NSLog(@"%@",@"Saved preview.html.");