We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to replace MapiMessage Attachments


How do i replace MapiMessage attachment through index ?

For example- If single MapiMessage item has 5 different attachments like-
attach4.txt and

and we need to replace all these attachments as-

All i need through index replacement of attachments. Can you please provide a sample code for this?


Could you please share sample input MSG and expected output MSG files here for our reference? We will then provide you more information on it.

Fwd_ This is test mail for outlook attachment.7z (598.5 KB)
Please find attached sample MSG file. This is the source/ input MSG file. This MSG file contains 5-different types of attachment files.
I need to compress each attachment files into .zip file and then replace the attachments in MSG file.

Please provide me a working code for this task.

Kind Regards


Please note that Aspose.Email does not provide APIs to compress the attachments. However, you can extract the attachments from MSG file using Aspose.Email and ZIP them using Aspose.ZIP. Please read the following article.

Zip or UnZip Files in C# - Compressing and Decompressing Archives

Once you ZIP the extracted files, you can add them to MSG as attachment. Please read the following article to add attachment.

Adding Attachment


I understand your points and I manage to extract and zip every attachments properly… My initial query is about how to attach .zip attachments using MapiMessage.

I don’t want to convert MapiMessage to MailMessage and then attach the attachments and then again convert MailMessage to MapiMessage.

Can you please assist me how to add attachments using MapiMessage?

Kind Regards,


Please use the attached sample project to replace the attachments using MapiMessage.
ReplaceAttach.zip (612.3 KB)