Sample code for 30+ languages & platforms
Perl

Save HTML Email Embedded Images

Saves HTML embedded items to files in a subdirectory. Images, style sheets, and anything else embedded within HTML, are not considered to be attachments. Instead, these items are "related item". The Chilkat email object provides a set of methods/properties for accessing the related items within an email.

Chilkat Perl Downloads

Perl
use chilkat();

$success = 0;

$email = chilkat::CkEmail->new();

#  Load an email object containing HTML with embedded images.

$success = $email->LoadEml("myEmails/HtmlEmail.eml");
if ($success != 1) {
    print $email->lastErrorText() . "\r\n";
    exit;
}

#  Iterate over the related items.  
#  Print the file name and save each to a file.
$i = 0;
$numRelated = $email->get_NumRelatedItems();
while ($i < $numRelated) {

    print $email->getRelatedFilename($i) . "\r\n";

    $success = $email->SaveRelatedItem($i,"myRelatedItemsDir");
    if ($success != 1) {
        print $email->lastErrorText() . "\r\n";
        exit;
    }

    $i = $i + 1;
}