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

Free Support Forum - aspose.com

Embedded image in an oft template mail - not in the text but as attachement

Hello,

I have a problem using Aspose Email Java.
I want to create an oft template with an Image inside.
Here my code :

public void generateOFT()
{
	String htmlBody = "";
	String savePath = "C:\\test.oft";

	MailMessage message = MailMessage.load(new ByteArrayInputStream(htmlBody.getBytes()),new HtmlLoadOptions());
	message.setSubject("Object");
	message.setFrom(new MailAddress( "test@test.it","test@test.it", false));
	message.setHtmlBody(htmlBody);

	MsgSaveOptions options = SaveOptions.getDefaultMsgUnicode();
	options.setSaveAsTemplate(true);
	message.save(savePath, options);
}

you can find the txt file attached with the htmlBody variable initialized. It’s to long to past here.
method.zip (9.3 KB)

When I open the oft file I have this view
image.png (9.3 KB)

So as you can see the embedded image is an attachment but not in the text.

Could you please help me.

Best Regards,

Riccardo
I’m using the last version of aspose email : aspose-email-18.5-jdk16

@GreenRic,

We need your sample input html file to look into it further at our end. This will help us analyze the issue and assist you further in this regard.

Hello @kashif.iqbal,

please find attached the sample input html file. inputString.zip (9.0 KB)

Thanks in advanced for your help,

Riccardo

@GreenRic,

We are investigating the issue you reported. We will let you know as soon as we have additional information.

@GreenRic,

We were able to reproduce the issue reported by you and have logged a ticket as EMAILJAVA-34422 in our issue tracking system against it. We will update you here as soon as we have additional information.

@GreenRic,

We were able to identify the issue. Loading MailMessage with HTML prepares the HTML and embeds the image in the body. Reassigning the body replaces the processed HTML.

message.setHtmlBody(htmlBody);

To resolve this issue, remove the code mentioned above. The code snippet for the complete solution is given below with the generated output attached at the end.

public void generateOFT()
{
    String htmlBody = "";
    String savePath = "C:\\test.oft";
    MailMessage message = MailMessage.load(new ByteArrayInputStream(htmlBody.getBytes()),new HtmlLoadOptions());
    message.setSubject("Object");
    message.setFrom(new MailAddress( "test@test.it","test@test.it", false));
    MsgSaveOptions options = SaveOptions.getDefaultMsgUnicode();
    options.setSaveAsTemplate(true);
    message.save(savePath, options);
}

generateOFTJava.zip (14.3 KB)

We hope that this resolved the issue you were facing. Please feel free to reach us if additional information is required.

Hello,

thanks for your reply.
It works perfectly!!!

Best Regards,

Riccardo