MailMessage.Load raises Exception

Hi,


Thank you so much for your reply.

Your solution worked out, but now having problem with calendar invitation mails.
If I add these mails exception is raised in MapiColleciton’s iterator next function.

Also attaching sample mails that generated this exception.

Exception is :

[19-Oct-2016_17:00:42,190] [ERROR] [mithi.files.pst.bulkadd.MapiMessageCollection(next)] - <“BEGIN” property should be at the first place in the properties>
Exception in thread “main” java.lang.IllegalStateExceptionjava.lang.IllegalStateException
at mithi.files.pst.bulkadd.MapiMessageCollection$MapiMessageEnumerator.next(MapiMessageCollection.java:78)
at mithi.files.pst.bulkadd.MapiMessageCollection$MapiMessageEnumerator.next(MapiMessageCollection.java:1)
at com.aspose.email.FolderInfo.addMessages(SourceFile:873)
at mithi.files.pst.GeneratePSTApp.createMailArchive(GeneratePSTApp.java:153)
at mithi.export.GenerateMailArchive.generateFiles(GenerateMailArchive.java:74)

at mithi.files.pst.GeneratePSTApp.createMailArchive(GeneratePSTApp.java:153)
at mithi.export.GenerateMailArchive.generateFiles(GenerateMailArchive.java:74)
at mithi.export.ExportMailAsPSTApp.generateMailArchiveFiles(ExportMailAsPSTApp.java:19)
at mithi.export.ExportMailArchiveApp.execute(ExportMailArchiveApp.java:37)

at mithi.export.ExportMailArchiveApp.execute(ExportMailArchiveApp.java:37)
at mithi.apps.jobs.RestoreMailApp.execute(RestoreMailApp.java:44)
at mithi.apps.jobs.RestoreMailApp.main(RestoreMailApp.java:71)
at mithi.apps.jobs.RestoreMailApp.main(RestoreMailApp.java:71)

Hi,


The exception stack is:

Exception in thread “main” class com.aspose.email.system.exceptions.ArgumentException: “BEGIN” property should be at the first place in the properties
com.aspose.email.ep.a(SourceFile:326)
com.aspose.email.ep.a(SourceFile:243)
com.aspose.email.ep.a(SourceFile:227)
com.aspose.email.MailMessage.r(SourceFile:4076)
com.aspose.email.MailMessage.b(SourceFile:4065)
com.aspose.email.MailMessage.a(SourceFile:3741)
com.aspose.email.MailMessage.a(SourceFile:203)
com.aspose.email.MailMessage.(SourceFile:197)
com.aspose.email.MailMessage.a(SourceFile:1627)
com.aspose.email.MailMessage.b(SourceFile:1540)
com.aspose.email.MailMessage.a(SourceFile:1343)
com.aspose.email.MailMessage.load(SourceFile:1328)
mithi.files.pst.bulkadd.MapiMessageCollection$MapiMessageEnumerator.next(MapiMessageCollection.java:63)
mithi.files.pst.bulkadd.MapiMessageCollection$MapiMessageEnumerator.next(MapiMessageCollection.java:1)
com.aspose.email.FolderInfo.addMessages(SourceFile:863)
mithi.files.pst.GeneratePSTApp.createMailArchive(GeneratePSTApp.java:153)
mithi.export.GenerateMailArchive.generateFiles(GenerateMailArchive.java:74)
mithi.export.ExportMailAsPSTApp.generateMailArchiveFiles(ExportMailAsPSTApp.java:19)
mithi.export.ExportMailArchiveApp.execute(ExportMailArchiveApp.java:37)
mithi.apps.jobs.RestoreMailApp.execute(RestoreMailApp.java:44)
mithi.apps.jobs.RestoreMailApp.main(RestoreMailApp.java:77)
at com.aspose.email.ep.a(SourceFile:326)
at com.aspose.email.ep.a(SourceFile:243)
at com.aspose.email.ep.a(SourceFile:227)
at com.aspose.email.MailMessage.r(SourceFile:4076)
at com.aspose.email.MailMessage.b(SourceFile:4065)
at com.aspose.email.MailMessage.a(SourceFile:3741)
at com.aspose.email.MailMessage.a(SourceFile:203)
at com.aspose.email.MailMessage.(SourceFile:197)
at com.aspose.email.MailMessage.a(SourceFile:1627) at com.aspose.email.ep.a(SourceFile:326)
at com.aspose.email.ep.a(SourceFile:243)
at com.aspose.email.ep.a(SourceFile:227)
at com.aspose.email.MailMessage.r(SourceFile:4076)
at com.aspose.email.MailMessage.b(SourceFile:4065)
at com.aspose.email.MailMessage.a(SourceFile:3741)
at com.aspose.email.MailMessage.a(SourceFile:203)
at com.aspose.email.MailMessage.(SourceFile:197)
at com.aspose.email.MailMessage.a(SourceFile:1627)
at com.aspose.email.MailMessage.b(SourceFile:1540)
at com.aspose.email.MailMessage.a(SourceFile:1343)
at com.aspose.email.MailMessage.b(SourceFile:1540)
at com.aspose.email.MailMessage.a(SourceFile:1343)
at com.aspose.email.MailMessage.load(SourceFile:1328)
at com.aspose.email.MailMessage.load(SourceFile:1328)
at mithi.files.pst.bulkadd.MapiMessageCollection$MapiMessageEnumerator.next(MapiMessageCollection.java:63) at mithi.files.pst.bulkadd.MapiMessageCollection$MapiMessageEnumerator.next(MapiMessageCollection.java:63)
at mithi.files.pst.bulkadd.MapiMessageCollection$MapiMessageEnumerator.next(MapiMessageCollection.java:1)
at com.aspose.email.FolderInfo.addMessages(SourceFile:863)
at mithi.files.pst.GeneratePSTApp.createMailArchive(GeneratePSTApp.java:153) at mithi.files.pst.GeneratePSTApp.createMailArchive(GeneratePSTApp.java:153)
at mithi.export.GenerateMailArchive.generateFiles(GenerateMailArchive.java:74)
at mithi.export.ExportMailAsPSTApp.generateMailArchiveFiles(ExportMailAsPSTApp.java:19)
at mithi.export.ExportMailArchiveApp.execute(ExportMailArchiveApp.java:37)
at mithi.apps.jobs.RestoreMailApp.execute(RestoreMailApp.java:44)
at mithi.apps.jobs.RestoreMailApp.main(RestoreMailApp.java:77)

Hi Archana,


Thank you for writing to us.

The issue is with the mail6345531847344074705.eml file that raises exception when loaded with MailMessage. It has been logged as EMAILJAVA-34204 in our issue tracking system for further investigation by our Product team. We’ll update you here once there is some information available in this regard.

Hi,


For the temporary solution can I ignore mail creating problem while adding to pst.

In my iterator next function it is triggering exception.

Can you provide solution such as just ignore that msg and continue to next so that at least complete operation will not get failed.
So generated pst will not contain that msg.

Hi Archana,


You can avoid this specific file by enclosing the message loading statement in try-catch block. This will avoid the message raising exception and add other messages to the PST without any issue. Please let us know if you need any further help in this regard.

Hi,

Thank you so much for the reply.

I did the same, added loading part in tru catch block.

public MapiMessage next()
{
try
{
MailMessage eml = MailMessage.load(files[position]);
//log.info(“attachments size:”+eml.getAttachments().size());
return MapiMessage.fromMailMessage(eml, MapiConversionOptions.getUnicodeFormat());
}
catch (IndexOutOfBoundsException e)
{
throw new IllegalStateException();
}
catch(com.aspose.email.system.exceptions.Exception e)
{
log.error("Aspose Email Exception while adding message to pst.Skipping this message, message index : " + position);
log.error(e.getMessage());
return new MapiMessage();
}
}

But what should I return from the catch block so that it will skip current message?

Hi Archana,


You can return “null” when you hit such a corrupt message and check at the receiving end for null value to skip such a message.