Free Support Forum - aspose.com

Corrupt MailMessage attachments saved w/ .msg formatted file (Outlook)

When trying to save a MailMessage as .MSG, the attachment in the MailMessage does affect the final size of the .MSG file, but when the .MSG file is opened with Outlook, and the attachment saved, Outlook saves the 300KB+ attachment as a 243 byte truncated and/or corrupt file.
This system needs to be able to save Aspose.Network.Mail.MailMessage objects to .msg formatted files that are fully compatible with all modern versions of Outlook.

Outlook 2010
Aspose.Network v6.6.0
.Net Framework 3.5

Reference DLL:
C:\Program Files (x86)\Aspose\Aspose.Network for .NET\Bin\net2.0\Aspose.Network.dll

code for saving, both methods:

public void saveOutlookMsgFile(ExchangeMessageInfo message, string filePath)
{
MailMessage msg = client_aspose.FetchMessage(message.UniqueUri);
msg.Save(filePath, MessageFormat.Msg);
}
public byte[] saveOutlookMsgFile(ExchangeMessageInfo message)
{
MailMessage msg = client_aspose.FetchMessage(message.UniqueUri);
MemoryStream ms = new MemoryStream();
msg.Save(ms, MessageFormat.Msg);
ms.Seek(0, SeekOrigin.Begin);
byte[] buff = null;
BinaryReader br = new BinaryReader(ms);
long numBytes = ms.Length;
buff = br.ReadBytes((int)numBytes);
br.Close();
ms.Close();
return buff;
}

Attached is the original file before the cycle, and the 2 .MSG files generated with the two different methods.

Hi,

Thank you for inquiry.

The original rar file is password protected. Could you please send the password to me using “Contact” --> “send saqib.razzaq an email”? I will check this message by first adding it to Outlook and then saving it with ExchangeClient.

Password sent via PM, however you won’t be needing it. The password protected stuff is just a random utility I happened to have
handy at the time, it modifies exe files to invoke UAC elevation.


The rar file isn’t even readable after 1 cycle, the contents of it are
beside the point, if winrar can’t even read it to see it needs a
password.


What I’m saying is that the rar file with the password is the attachment being corrupted/truncated. The .MSG test files are without password protection.

Thanks for your time. I hope you can figure this out. If you need anything else, I’ll be refreshing this thread.

Hi,

I created a new email with Outlook, attached the original rar file and sent it to an email address. I verified that the email + attachment could be opened using Outlook correctly. When I downloaded the message using Aspose.Network’s ExchangeWebServiceClient.FetchMessage() and saved it as MSG, the message and rar attachment opened correctly in Outlook 2010/Winrar.

Attached are 2 files:
saved using Aspose.msg: I used the below code to save this message.
saved using Outlook.msg: Directly saved from Outlook 2010 connected to Exchange 2010 server

Code to save file:
ExchangeWebServiceClient client = new ExchangeWebServiceClient(mailboxURI, credential);
… read inbox folder
// Save the message in MSG format
MailMessage msg = client.FetchMessage(msgInfo.UniqueUri);
msg.Save(i + “.msg”, MailMessageSaveType.OutlookMessageFormat);

Could you please attach the original MSG file by directly saving it from Outlook 2010? I will check this by placing it in my own Inbox and see if I can find any problem.

Here you are, saved from Outlook 2010. I confirm that inbox.zip is not corrupted when using Outlook 2010.

We are using Aspose.Network v6.6.0.

Hi,

Thank you for the test file. I placed it in Outlook 2010 Inbox folder, which is connected to Exchange 2010 and used ExchangeWebServiceClient class to fetch the message. The message was saved successfully and I could open the attachment in winrar.

I have the following environment:
Server:
Exchange Server 2010

Client:
Outlook 2010
Visual Studio 2008 and .NET Framework 3.5
Windows 7 x64
Aspose.Network for .NET v6.7

Could you please provide some details about your environment, so that I could reproduce the issue at my end?

MailMessage msg = client_aspose.FetchMessage(message.UniqueUri);
Which class are you using to connect to Exchange. ExchangeClient or ExchangeWebServiceClient?

Aspose.Network for .NET v6.7

we are trying to use 6.0

looks like we will have to either renew our license, or roll back to 5.5.0.1 (I think)

We just renewed our license, and I tried Aspose.Network for .NET v6.7. It does the same exact thing! There’s only so much useful information I can feed you.


Outlook 2010
Aspose.Network v6.7.0
.Net Framework 3.5

Reference DLL:
C:\Program Files (x86)\Aspose\Aspose.Network for .NET\Bin\net2.0\Aspose.Network.dll

client_aspose = new ExchangeWebServiceClient(ews_url, new NetworkCredential(user, pass, “”));
I also tried changing to the net3.5 version, and still no joy.
I did a bytewise comparison of the output of the 2 save methods (above), and they are different:

The MemoryStream method corrupts, while the file method does not!

byte mismatch at position: 328322
byte mismatch at position: 328323
byte mismatch at position: 328324
byte mismatch at position: 328325
byte mismatch at position: 328326
byte mismatch at position: 328327
byte mismatch at position: 328329
byte mismatch at position: 328331
byte mismatch at position: 328332
byte mismatch at position: 328333
byte mismatch at position: 328334
byte mismatch at position: 328337
byte mismatch at position: 328338
byte mismatch at position: 328339
byte mismatch at position: 328341
byte mismatch at position: 328342
byte mismatch at position: 328343
byte mismatch at position: 328344
byte mismatch at position: 328346
byte mismatch at position: 328347
byte mismatch at position: 328348
byte mismatch at position: 328349
byte mismatch at position: 328350
byte mismatch at position: 328351
byte mismatch at position: 328352
byte mismatch at position: 328353
byte mismatch at position: 328354
byte mismatch at position: 328355
byte mismatch at position: 328356
byte mismatch at position: 328357
byte mismatch at position: 329640
byte mismatch at position: 329641
byte mismatch at position: 329642
byte mismatch at position: 329656
byte mismatch at position: 329657
byte mismatch at position: 329658
byte mismatch at position: 331408
byte mismatch at position: 331409
byte mismatch at position: 331410
byte mismatch at position: 331424
byte mismatch at position: 331425
byte mismatch at position: 331426
byte mismatch at position: 331440
byte mismatch at position: 331441
byte mismatch at position: 331442
byte mismatch at position: 331456
byte mismatch at position: 331457
byte mismatch at position: 331458

I may just end up going back to the file method, and construct some sort of temp file solution that deletes the temp file immediately after reading it into a byte[] variable. I really need a non file solution for this, as all sorts of issues can crop up when using files!

After further testing, it seems that the data is being corrupted by something else, and not Aspose.Network!

opened an offending msg file in notepad.exe and found:

FILE QUARANTINED

The original contents of this file have been replaced with
this message because of its characteristics.
File name: 'Test - Attachment [2011-08-10T16 28 16Z]HGMR.msg->fixuac.rar’
Virus name: 'CorruptedCompressedFile’

This happens after the file is sent through another system. I had made an error while testing to make sure the files before/after that system to make sure it isn’t being altered. Appearantly the system the file is being sent to doesn’t like password protected archives, and treats them as viruses. At least now I know that there is a bit of post processing responsible for this, and not Aspose.