Can you get the bytes[] of the new Outlook message after adding attachments?

I am evaluating the Java aspose-email library. I am able to load an Outlook msg file using MapiMessage msg = MapiMessage.load(inputStream), add I am able to add some attachments to that Outlook msg, but I don’t see how I can get the resulting msg bytes[] in code after adding the new attachments?

The only way I can see to accomplish this is to use the API save(…) method, to save the Outlook msg to a file, and then read the file again using Java I/O. However, I don’t want to spend the time doing file I/O to accomplish this, is there anyway from the API to get the newly built Outlook msg in code without using the save(…) method and re-reading the file? Thanks.

@paul37

Your understanding is correct. You need to call the save method and load the MSG file again. However, you can work with added attachment using MapiMessage that is already loaded. Could you please share the complete detail of your use case why you need to stream after adding attachment? We will then provide you more information on it.

@tahir.manzoor, the use case is to design an integration service to retrieve Outlook MSG files from a repository system, manipulate them to add some attachments (evaluating Aspose for this step), and then return the resulting Outlook MSG file to the caller. This may be passed off to the browser for a user to download or the modified MSG file will be saved back into the repository system again. No where along that process would we desire to save it to a network share or file system. I feel like the Aspose API save() method should not default to saving the file to the file system as there are many libraries and plain old Java I/O that can easily do that for me already. Having to write to disk, re-load from disk, is a lot of network and or file I/O that will slow our process down, especially when dealing with millions of MSG files. Is there anyway to work around this in the Aspose API? I really just want the save() method to return the bytes instead of returning void and writing to disk, or just another Aspose API method that “builds” the new MSG file and returns the bytes. Thanks.

@paul37

We have logged a ticket for your requirement as EMAILJAVA-35059. You will be notified via this forum thread once this feature is available.

We apologize for your inconvenience.

Thank you @tahir.manzoor! This may be too much to ask, but do you have a general idea on the timeframe? Are we talking months to implement this feature, or maybe just a couple of weeks, or even sooner? I ask because I’m working on evaluating Aspose for our use case for my company to decide before purchasing. This was one issue that was holding us back a bit. Thanks again.

@paul37

We suggest you please use the following code example to achieve your requirement. Hope this helps you.

MapiMessage msg = MapiMessage.load(bis);
// some modification
// ...
//
ByteArrayOutputStream bos = new ByteArrayOutputStream();
msg.save(bos);
byte[] data = bos.toByteArray();

@tahir.manzoor, that will work perfectly. I must have overlooked that overloaded save(…) method that accepted an OutputStream. Thanks for pointing that out. This issue is resolved.

@paul37

Thanks for your feedback. We have closed the issue EMAILJAVA-35059.