Msg to mhtml - the external image present in this msg file is not visible in the output mhtml file

language: java21
library aspose-email:25.1

During msg to mhtml conversion , the external image present in this msg file is not visible in the output mhtml file. please help to fix this problem

input
Develop Software 1.zip (34.1 KB)

output file
output_Develop Software.zip (27.8 KB)

@divine1

When converting a MSG file to MHTML format using Aspose.Email, if external images are not appearing in the output MHTML file, there are a few steps you can take to troubleshoot and potentially resolve the issue.

  1. Ensure External Images are Accessible: Make sure that the external images referenced in the MSG file are accessible from the environment where the conversion is taking place. If the images are hosted on a server, ensure that the server is reachable and that there are no network issues.

  2. Check MHTML Format Options: When saving the email as MHTML, you can customize the saving process. Ensure that you are not excluding images or other resources. You can use the MhtFormatOptions to control how the MHTML file is generated. For example, you might want to include options that ensure all resources are embedded correctly.

    Here’s a sample code snippet to save an email as MHTML with options:

    import com.aspose.email.MailMessage;
    import com.aspose.email.SaveOptions;
    import com.aspose.email.MhtFormatOptions;
    
    public class EmailToMhtml {
        public static void main(String[] args) {
            // Load the MSG file
            MailMessage message = MailMessage.load("path/to/your/message.msg");
    
            // Set MHTML save options
            SaveOptions options = SaveOptions.DefaultMhtml;
            options.MhtFormatOptions = MhtFormatOptions.WriteHeader | MhtFormatOptions.HideExtraPrintHeader;
    
            // Save the email as MHTML
            message.save("path/to/save/email.mhtml", options);
        }
    }
    
  3. Check for Image Links: If the images are linked rather than embedded, ensure that the links are correct and that the images are still available at those links. If the images are not embedded, they may not appear in the MHTML file if the links are broken.

  4. Update Aspose.Email Library: Ensure that you are using the latest version of the Aspose.Email library. Sometimes, issues are resolved in newer releases, so updating to the latest version may help.

If you continue to experience issues after trying these steps, consider reaching out to the Aspose support forum for further assistance, providing details about your specific scenario and any error messages you may encounter.

Sources:
[1]: C# Guide - Saving Email as MHTML File - Aspose

Hello @divine1 ,

Could you please clarify the issue with the external resource? Which image is not visible? Is it the image in the page header?

<img alt="How to Develop Software" width="2560" style="width: 2560px; height: auto; max-width: 100%; margin: 0px 0px 50px; box-sizing: border-box;" 
src="https://newvision-software.com/wp-content/uploads/2024/12/How-to-Develop-Software-scaled.webp">

@sergey.vivsiuk i have attached the input msg file in my question.

when i open this msg file, all images are visible. when this msg file is converted to mhtml, the images are missing in mhtml file.

i have attached the output mhtml file too. could you convert the msg to mhtml and verify it?

i tested with aspose-email 25.2

input_Develop Software 1.zip (34.1 KB)

output_Develop Software 1.7z (26.5 KB)

Hello @divine1 ,

Aspose.Email for Java 25.2 now supports extracting image-linked content from the HTML body and embedding it as attachments in MIME messages. This enhancement ensures that linked images are preserved and properly associated with the email, improving content integrity and offline accessibility.

API Changes:

  • Added HtmlSaveOption.ExtractHTMLBodyResourcesAsAttachments, defines whether to extract HTML body resources as attachments

Code Example:

MapiMessage mapiMessage = MapiMessage.load("test.msg");
MhtSaveOptions so = SaveOptions.getDefaultMhtml();
so.setExtractHTMLBodyResourcesAsAttachments(true);
so.setResourceHtmlRenderingHandler(new ResourceHtmlRenderingHandler() {
    public void invoke(final Object sender, final ResourceHtmlRenderingEventArgs e) {
        if (sender instanceof Attachment)
            System.out.println(e.getPathToResourceFile() + " " + ((Attachment) sender).getContentId());
    }
});
mapiMessage.save("test.mht", so);