Free Support Forum - aspose.com

MapiTask creation from mimeContent throwing Exception

Hello,

I’m trying to create a MapiTask using the following code:

InputStream stream = new ByteArrayInputStream(rawTaskDecoded,0,rawTaskDecoded.length);
				
MailMessage mailMessage = MailMessage.load(stream);
MapiMessage mapiMessage = MapiMessage.fromMailMessage(mailMessage);

MapiTask task1 = (MapiTask) mapiMessage.toMapiMessageItem();

When running it, the following exception is happening:

com.aspose.email.MapiMessage cannot be cast to com.aspose.email.MapiTask

I can create a MapiNote using this code, but when using it to create a MapiTask it does not work.
What can I do to solve this?

Thanks

@kelberuc

I suggest you to please visit this documentation link for your kind reference. I hope the shared information will be helpful.

@mudassir.fayyaz

I’m afraid the code in the shared documentation link is throwing exception too

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET
MapiMessage msg = MapiMessage.FromFile(dataDir + "Contact.msg");
MapiContact mapiContact = (MapiContact)msg.ToMapiMessageItem();

The above code throws the same exception as mine.

com.aspose.email.MapiMessage cannot be cast to com.aspose.email.MapiContact

I’m using Aspose.Email for Java 20.9

@kelberuc

Can you please be kind enough to share the source file so that I may try reproducing this on our end and help you out.

Hi @mudassir.fayyaz,

Please find below my code:

File file = new File("MimeContent");
InputStream stream = new FileInputStream(file);
MailMessage mailMessage = MailMessage.load(stream);
MapiMessage mapiMessage = MapiMessage.fromMailMessage(mailMessage);
MapiTask task1 = (MapiTask) mapiMessage.toMapiMessageItem();

MimeContent.zip (501 Bytes)

Thanks

@kelberuc

I have created an issue with ID EMAILJAVA-34752 in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.