Sample code for 30+ languages & platforms
Java

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 Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    CkEmail email = new CkEmail();

    //  Load an email object containing HTML with embedded images.

    success = email.LoadEml("myEmails/HtmlEmail.eml");
    if (success != true) {
        System.out.println(email.lastErrorText());
        return;
        }

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

        System.out.println(email.getRelatedFilename(i));

        success = email.SaveRelatedItem(i,"myRelatedItemsDir");
        if (success != true) {
            System.out.println(email.lastErrorText());
            return;
            }

        i = i+1;
        }
  }
}