Msg file sender address is invalid in outlook

Hi,


I’m trying to remove attachments from a .msg file and save the email to disk using the MailMessage class.

MailMessage origMessage = MailMessage.load(
“C:\Temp\new.msg” ), MessageFormat.getMsg());

origMessage.getAttachments().clear();

FileOutputStream fileOut = new FileOutputStream(“C:\Temp\testupload.msg”);
origMessage.save(fileOut, MailMessageSaveType.getOutlookMessageFormat());


The saved email’s from address is in the following (exchange?)format:

“firstname lastname” </O=TEST/OU=TEST1/CN=RECIPIENTS/CN=TEST>

When the saved email is opened in Outlook, the sender name is not recognised/interpreted by Outlook as its doesnt have the email address. The to/cc/bcc addresses look correct.

Is there a way to get the email address of the sender of an .msg file using MailMessage or to get the sender/from address to be in the format that Outlook understands?

I’ve attached a sample .msg file as well as a screenshot of the saved email once opened from Outlook.

Hi Chamindu,


Thank you for your inquiry.

I have tested your said issue with latest version of Aspose.Email for Java v1.2.0 and a sample file (with attachments) of my own. I was unable to replicate the problem at my end. The email address in From field of the resultant message is in Smtp format i.e. “from@domain.com”. Please give a try to the latest version and feed us back with your results.

I believe you have shared your output file with us, cause it doesn’t have any attachments. We will require your input message file so we may test the issue on our end.


Looking forward for your response.

Hi,


The sample input file I used (testupload.msg) has been attached to this post.i.e. testupload.zip.It doesn’t have any attachments but the problem with the invalid sender address happens with or without attachments.

I’m using “aspose-email-1.2.0-java” library which I believe is the latest version.

Can you please try with the sample file testupload.msg?

thanks
Chamindu

Hi Chamindu,


Thank you for your response.

Yes, Aspose.Email for Java v1.2.0 is the latest version and I am able to observe the said behaviour with your provided sample file (testupload.msg). I have logged an investigation in our tracking system to probe further into this matter. The ticket Id for your reference is NETWRKJAVA-33118.

I have also observed that the said problem is reproduce-able with just this file. I have tried several other message files (with or without attachments) but unable to replicate the issue. So, I would like to know the origin of specified message.

Thanks and Regards,

Hi,


Thanks for logging a ticket. Good to know you can reproduce the issue.
The input file was saved from Outlook 2007. However I have observed the same behavior when messages are saved from Outlook 2003 as well.
The issue only happens if the sender is from within our organisation/domain and only with the sender address, the to/cc/bcc addresses are interpreted correctly even if they are from within the organisation.

Does this have anything to do with the fact that we use Exchange Server?

thanks & regards

Hi Chamindu,


Thank you for providing the further details in this regard. The new information will definitely help us in sorting out the cause of problem. I have attached your comments to the ticket already associated with this thread and we will keep you posted with updates on this.

Regards,

Hi,


I was wondering if there has been any progress on this issue?


Regards,

Hi,


I am afraid that I haven’t received any updates in this regard. Although I have requested the development to provide an ETA. As soon as I get any further details, I will post here for your reference.

Thank you for your patience.

Hi,


Is there any update on this issue?
If you can provide some kind of ETA that would be good. I’m doing an evaluation of this library for our company and I need to give a resolution for this issue or at least be able to say a solution is on the way.

Any feedback would be greatly appreciated as I’m waiting to give the go ahead to purchase this library.

thanks & regards!

Hi,


I am afraid, I have not received any updates on this issue in particular to the Java version of Aspose.Email component. Although, we were able to reproduce the said problem with Aspose.Email for .NET v1.4.0. So we have logged a separate ticket and currently we are trying to find out the cause of this behaviour. As soon as our investigation is complete, we will move forward to fix the problem (for both .NET and Java) and then we will be able to share an ETA.

Meanwhile, I am looking for any possible workaround for your situation. One possible workaround is to load the message in an instance of MapiMessage instead of MailMessage. Please check the below source code for your reference,

Java
MapiMessage origMessage = MapiMessage.fromFile(“testupload.msg”);
origMessage.getAttachments().clear();
FileOutputStream fileOut = new FileOutputStream(“output.msg”);
origMessage.save(fileOut);

Hi,


Thanks for the info & the workaround suggested.
Unfortunately I need to use the MailMessage class as it works more accurately in some of the other functionality I need including:
- extracting embedded emails & their attachments (non-embedded images)
- saving each email & its embedded email without attachments it its native format e.g. .eml or .msg

I found that MapiMessage behaves inconsistently in some of the above areas.

MailMessage class works well for both formats in all the areas with the exception of this particular issue. I am reluctant to change the all my code as it will be significant effort to retest all the functionality and I will have to still log issues with you for the areas that MapiMessage doesn’t work.

I tried the following workarounds with no luck:

1) convert MailMessage to MapiMessage using the line below but the sender address still ends up being incorrect:

MapiMessage mapiMsg = MapiMessage.fromMailMessage(origMessage);

2) extract the from address from MapiMessage and set it in MailMessage:

origMessage.getHeaders().set(“From”, mapiMsg.getHeaders().get(“From”));

But the sender address is wrong in certain scenarios or examples of .msg files.

Regards,



Regards,
Chamindu
Hi Chamindu,

Thank you for the further elaboration.

We are currently working on this issue. As soon as I get any updates, I will let you know here.

chEmailTest:
I found that MapiMessage behaves inconsistently in some of the above areas.

Will you be kind enough to provide us some samples showing inconsistent behaviour of MapiMessage class? We will look into them as well.

Regards,

Hi,


I’ve tried to use the MapiMessage class and found that this class solved the invalid sender address issue.
However, I have a problem when I try to remove one or more attachments from the email.

Basically I need to make sure the email is stripped of all attachments and saved with any embedded images in the body. When the MapiMessage class is used embedded images and normal attachments are both found in the attachment collection. So I tried to identify the attachments that aren’t embedded images and only remove them. But when I do this and try to open the email I get an error “Could not open one or more attachments”.

Here is my code:

MapiMessage origMessage = MapiMessage.fromFile(“C:\Temp\inputfiles\test2\test email with embedded images.msg”);
for (int i = 0; i < origMessage.getAttachments().size(); i++)
{
MapiAttachment attachment = (MapiAttachment) origMessage.getAttachments().get(i);
if (attachment.getProperties().contains(0x3712001E) || attachment.getProperties().contains(0x3712001F)) {
// Embedded image leave it in the email
} else {
// Normal attachment, remove from the email
origMessage.getAttachments().remove(i);
i = i - 1;
}
}

origMessage.save(“C:\Temp\inputfiles\test2\out.msg”);

The problem appears to be because I am trying to remove an item from the collection when there are other items after it. The problem can also be reproduced by doing the following:

MapiMessage origMessage = MapiMessage.fromFile(“C:\Temp\inputfiles\test2\test email with embedded images.msg”);
origMessage.getAttachments().remove(0);
origMessage.save("C:\\Temp\\inputfiles\\test2\\out.msg");

When you open "out.msg" it will show the error I mentioned earlier. I've attached the input file I used for this to the post.

What is the best way to remove items from the attachments collection at different positions?

Regards,

Hi Chamindu,


Thank you for providing us further details and your sample. We are currently looking into it to suggest you a feasible solution for your said problem. Please spare us some time for the analysis.

Regards,

Hi Chamindu,


Sorry for the delayed response on this.

We found that your said issue is correct while using the MapiMessage class to remove any regular attachments. We are still looking into it to provide you a workaround for your situation.

Hi,


Glad to hear you can reproduce the issue. I really hope you can find a solution for this.

thanks & regards,

Hi,


I am afraid, I was unable to find a solution for your problem related to the attachments in MapiMessage class. I have forwarded a request to the development team in this regard. I will let you know as soon as I hear anything from their end.

We are sorry for your troubles.

Regards,

Hi,

Has there been any progress on this issue?

My company has purchased this library and so I would like to see if someone can look at this with priority? What do I need to do?

Is there a separate forum for customers?

Regards,

Hi Chamindu,


Sorry for the delayed response.

We have completed the investigation on your inquiry and we have found that your provided sample message (testupload.msg) already has the sender address in Exchange format. This could be due to some settings of your Exchange Server, that is why we were unable to replicate the said issue with other samples.

The investigation concluded that Aspose.Email component is not altering the sender address but merely displaying it in it’s correct format (ABC XYZ</O=MBL/OU=MBL1/CN=RECIPIENTS/CN=CHATHTHO>). I have requested the development team to check if we can fix this behaviour so that after processing with Aspose.Email component, the sender address remains as “ABC XYZ”.

Regarding your inquiry of using MapiMessage class for removing the regular attachments, please find below the sample code for your need,

Java

int count =0;
MapiMessage origMessage = MapiMessage.fromFile(“test email with embedded images.msg”);
MapiAttachmentCollection attachments = origMessage.getAttachments();
count = attachments.size();
System.out.println("Total attachments " + count);
for (int i = count - 1; i >= 0; --i)
{
MapiAttachment attachment = (MapiAttachment) attachments.get(i);
//check if attachments is inline
if (attachment.getMyProperties().contains(MapiPropertyTag.PR_ATTACHMENT_FLAGS) && attachment.getMyProperties().get(MapiPropertyTag.PR_ATTACHMENT_FLAGS).getInt32() == 8)
{
//Save inline/embedded attachments
System.out.println("Preserved " + attachment.getLongFileName());
}
else
{
//delete regular attachments
attachments.remove(attachment);
System.out.println("Deleted " + attachment.getLongFileName());
}
}
FileOutputStream fileOut = new FileOutputStream(“output.msg”);
origMessage.save(fileOut);


chEmailTest:

Is there a separate forum for customers?

Most of the support is provided through this forum and we do not have separate forums for “Customers Only”. Although, we have Priority and Enterprise Support forums.

Hi,

Thank you for your response.

I am satisfied with your answer regarding the sender address in exchange format, I will attempt to find a work around for this. Thanks for spending the time investigating it.

With regards to the MapiMessage removing regular attachments sample code I have tried it and found 2 issues:

1) The constant MapiPropertyTag.PR_ATTACHMENT_FLAGS is not defined in Aspose.Email for Java 1.2.0. I used the following code to test for embedded images, is this correct?

if (attachment.getProperties().contains(0x3712001E) || attachment.getProperties().contains(0x3712001F))

2) When I run the sample code and open the saved "output.msg" file in Outlook 2007 I get an error "Could not open one or more attachments" and the message has one of the embedded images missing.



Lastly, can I also please ask a favour? Can you please remove my full name from the previous post so this post doesnt turn up when someone google's my name? thanks!

Regards,

C