We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Save to OFT with Embedded Images

Is there a way to, via a setting or function, have al images saved as embedded images when saving an HTML to OFT?

@Johan_du_Toit,

Thank you for writing to Aspose support team.

You may please give a try to the following sample code where html contains embedded images:

Aspose.Email.HtmlLoadOptions options = new Aspose.Email.HtmlLoadOptions();
MailMessage message2 = MailMessage.Load(@"Sample.html", options);
message2.Save(@"Sample.oft", MsgSaveOptions.DefaultMsgUnicode);

If you have html and resources folder, then give a try to the following sample code:

Aspose.Email.HtmlLoadOptions options = new Aspose.Email.HtmlLoadOptions();
options.PathToResources = @"D:\Test_files\";
MailMessage message2 = MailMessage.Load(@"D:\Test.html", options);
message2.Save(@"D:\Test.oft", MsgSaveOptions.DefaultMsgUnicode);

Hi,

The steps in your sample code does not seem to work.

My html is not on disk,but in memory. Herewith my code that takes similar steps than yours.

var html = EmbedImages(Template.Html);

        using (var textStream = new MemoryStream(Encoding.UTF8.GetBytes(html)))
        {
            using (var emailMessage = MailMessage.Load(textStream, new Aspose.Email.HtmlLoadOptions()))
            {
                emailMessage.Subject = Template.Subject;

                var options = SaveOptions.DefaultMsgUnicode;
                options.SaveAsTemplate = true;
                emailMessage.Save(filePath, options);
            }
        }

Attached the html:
Html.zip (87.7 KB)

The Result:
Result.png (29.5 KB)

Please advise.

Further more, where can I download the latest version of the component? https://downloads.aspose.com/ only provides version 17.9.0.0.

@Johan_du_Toit,

I have tried your sample code as follows and observed no issue. The resultant oft file contains image properly. Could you please download the latest version here and give it a try again?

var html = File.ReadAllText(@"Html.txt");
//var html = EmbedImages(Template.Html);

using (var textStream = new MemoryStream(Encoding.UTF8.GetBytes(html)))
{
    using (var emailMessage = MailMessage.Load(textStream, new Aspose.Email.HtmlLoadOptions()))
    {
        emailMessage.Subject = "Template.Subject";

        var options = Aspose.Email.SaveOptions.DefaultMsgUnicode;
        options.SaveAsTemplate = true;
        emailMessage.Save(@"Html.oft", options);
    }
}

Output.zip (210.8 KB)

Hi,

I have opened the oft in your output file and I still see the same result. Seems like the OFT is opening in text view, instead of HTML view. Please see attached video. Which version of outlook did you test it with? I am using Outlook 2013.

When I do not embed the images, then the OFT opens fine.

ScreenCapture_2018-4-12 16.44.03.zip (317.6 KB)

@Johan_du_Toit,

This seems to be an issue with Outlook 2016 and above that we have just noticed. It has been logged as EMAILNET-38960 for further investigation at our end. We’ll update you here once there is some information or a fix version available in this regard.

The issues you have found earlier (filed as EMAILNET-38960) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by kashif.iqbal

Hi,

I have downloaded v18.4 and tested on Outlook 2013 as in my original post and I am still getting the same erroneous result. Please advise.

@Johan_du_Toit,

We have tried to reproduce the issue at our end. OFT was generated successfully. The resultant file contains the images. Screenshot is attached for your reference.

html_to_oft_output.jpg (196.4 KB)

Please provide me with the produced OFT so I may test on my side. Did you test with Outlook 2013?

Would it be possible to send me the code you used to generate the OFT with embedded images, including the code used to embed the images in the HTML.
It is imperative that the HTML is loaded from and saved to a stream and not a file on disk.

Thank you in advance.

@Johan_du_Toit,

We have tested it using the following sample code:

var html = File.ReadAllText(@"Html.txt");
//var html = EmbedImages(Template.Html);

using (var textStream = new MemoryStream(Encoding.UTF8.GetBytes(html)))
{
    using (var emailMessage = MailMessage.Load(textStream, new Aspose.Email.HtmlLoadOptions()))
    {
        emailMessage.Subject = "Template.Subject";

        var options = Aspose.Email.SaveOptions.DefaultMsgUnicode;
        options.SaveAsTemplate = true;
        emailMessage.Save(@"Html.oft", options);
    }
}

Output was tested with this version of Outlook (which is Outlook 2016). Sample html file and output generated is attached here html.zip (183.2 KB)
for your reference.

Thank you very much. I have tested with the new version and it works perfectly!

A post was split to a new topic: HTML to EML raises exception