Getting exception in MapiMessage while reading outlook 365 file


Hi,

I have written a program to read an oulook msg data from a folder.
The Folder has two messages. One which is created using program as below :
//********************************************************************

String strBaseFolder = "C:\\Lap_C_Drive\\APOSEMAILS";

System.out.println("Creating new messages....");

MailMessage message = new MailMessage();

message.setFrom(new MailAddress("atul.bhadauria@xchanging.com", "Atul Singh", false));

message.getTo().addItem(new MailAddress("atul.bhadauria@xchanging.com", "Atul Singh"));
message.getTo().addItem(new MailAddress("atuls.work@gmail.com", "ATUL2", false));
message.setSubject("New message created by Aspose.Email for Java");

message.setHtmlBody("This line is in bold.

" +

"This line is in blue color");


message.save(strBaseFolder + "Message.msg", SaveOptions.getDefaultMsg());

System.out.println("Messages created successfuly");
//***********************************************************

//**************************************************************

The other file is manually saved from my outlook 365.
I have attached both the outlook messages.

The issue is I am getting an exception in reading the message from outlook 365 while other created from program is working successfully.

My Program is below :

*********************************
public class MissingSequence {
public static void main(String[] args) throws SQLException, ClassNotFoundException{

File folder = new File("C:\\Lap_C_Drive\\APOSEMAILS\\");
File[] listOfFiles = folder.listFiles();

for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("File " + listOfFiles[i].getName());
try
{
MapiMessage outlookMessageFile=MapiMessage.fromFile(folder + listOfFiles[i].getName());
System.out.println("OutlookMessageFile::: " + outlookMessageFile);
//Display sender's name
System.out.println("Sender Name : " + outlookMessageFile.getSenderName());

//Display Subject
System.out.println("Subject : " + outlookMessageFile.getSubject());

//Display Body
System.out.println("Body : " + outlookMessageFile.getBody());

//Display Recipient's info
System.out.println("\nRecipients : \n");
//Loop through the recipients collection associated with the MapiMessage object
for (int j=0; j<outlookMessageFile.getRecipients().size(); j++)
{
//Set a reference to the MapiRecipient object
MapiRecipient rcp= (MapiRecipient) outlookMessageFile.getRecipients().get_Item(j);
//Display recipient email address
System.out.println("Email : " + rcp.getEmailAddress());
//Display recipient name
System.out.println("Name : " + rcp.getDisplayName());
//Display recipient type
System.out.println("Recipient Type : " + rcp.getRecipientType());
}
}
catch(Exception ex)
{
System.out.println("Some error occurred while parsing the msg file.");
}

}
}

}
***************************************

Output is **********
run:
File Message.msg
OutlookMessageFile::: com.aspose.email.MapiMessage@18bbc5a
Sender Name : Atul Singh
Subject : New message created by Aspose.Email for Java(Aspose.Email Evaluation)
Body : This is an evaluation copy of Aspose.Email for Java
View EULA Online: http://www.aspose.com/corporate/purchase/end-user-license-agreement.aspx
------------------------------

This line is in bold.

This line is in blue color


Recipients :

Email : atul.bhadauria@xchanging.com
Name : Atul Singh
Recipient Type : 1
Email : atuls.work@gmail.com
Name : ATUL2
Recipient Type : 1
File Missing Sequence - 132698.msg
Some error occurred while parsing the msg file.
BUILD SUCCESSFUL (total time: 3 seconds)

//***************
Can you please help and suggest a possible solution.

Regards
Atul Singh

Hi Atul,

Thank you for contacting Aspose Support team.

We have tested this issue at our end with the latest version of Aspose.Email for Java 6.2.0 and were not able to reproduce the issue at our end. The second file is also read successfully and information is displayed properly. I have modified your code a little to access the files from a folder (where we have put these files) and displayed proper exception message in try catch block. Please modify your code accordingly and share the exception message details with us for our investigation.

Code:

File folder = new File(“690863\”);
File[] listOfFiles = folder.listFiles();

for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
System.out.println("------------------------ File " + listOfFiles[i].getName() + “--------------------------------”);
try
{

MapiMessage outlookMessageFile = MapiMessage.fromFile(folder + “\” + listOfFiles[i].getName());

//Display sender’s name
System.out.println("Sender Name : " + outlookMessageFile.getSenderName());

//Display Subject
System.out.println(“Subject : " + outlookMessageFile.getSubject());

//Display Body
System.out.println(“Body : " + outlookMessageFile.getBody());

//Display Recipient’s info
System.out.println(”\nRecipients : \n”);
//Loop through the recipients collection associated with the MapiMessage object
for (int j=0; j<outlookMessageFile.getRecipients().size(); j++)
{
//Set a reference to the MapiRecipient object
MapiRecipient rcp= (MapiRecipient) outlookMessageFile.getRecipients().get_Item(j);
//Display recipient email address
System.out.println("Email : " + rcp.getEmailAddress());
//Display recipient name
System.out.println(“Name : " + rcp.getDisplayName());
//Display recipient type
System.out.println(“Recipient Type : " + rcp.getRecipientType());
}
}
catch(Exception ex)
{
System.out.println(”--------------------------------” + ex.getMessage() + “----------------------------------”);
}
}
}

Thanks you so much for your reply.

Amending // while reading the file has resolved the issue.

You have been really very helpful.

Thanks
Atul

Hi Atul,

Thank you for sharing your feedback. Please feel free to contact us if you have any further query related to Aspose.Email API.