Free Support Forum -

How to convert between System.Net.Mail.MailMessage and Aspose.Network.Mail.MailMessage?


Does anybody know if there is a method available to convert a System.Net.Mail.MailMessage to or from a Aspose.Network.Mail.MailMessage? I figure this sort of thing should be fairly simple, and I expected it to be part of the Aspose library, but I can’t find anything…

Suggestions appreciated!


This message was posted using Page2Forum from MailMessage Class - Aspose.Network for .NET

Hi Rik,

Thank you for inquiry.

I am sorry, there is no such method or utility for this kind of conversion. Most of the constructors, methods and properties of Microsoft’s and Aspose’s MailMessage are identical. Could you please try to remove the System.Net.Mail and add Aspose.Network.Mail and update code to fix any errors?

using Aspose.Network.Mail;
//using System.Net.Mail;

Below is an example of basic usage of both Microsoft and Aspose’s MailMessage. I just updated the namespace in class names and both examples compiled and worked successfully.

// Microsoft example
System.Net.Mail.MailMessage msMessage = new System.Net.Mail.MailMessage();
msMessage.Subject = “test”;
msMessage.From = new System.Net.Mail.MailAddress("");
msMessage.To.Add(new System.Net.Mail.MailAddress(""));

// Aspose example
Aspose.Network.Mail.MailMessage asposeMessage = new Aspose.Network.Mail.MailMessage();
asposeMessage.Subject = “test”;
asposeMessage.From = new Aspose.Network.Mail.MailAddress("");
asposeMessage.To.Add(new Aspose.Network.Mail.MailAddress(""));


Thanks for the reply.

Unfortunately I can’t do this as I am writing a framework, and I don’t want to expose the Aspose objects outside my classes.

The method I’m currently writing takes in a System.Net.Mail.MailMessage, and returns a byte[] which represents an Outlook Mapi message file.



In this case, you may write your own utility class/method that copies all properties from System.Net’s MailMessage to Aspose.Network’s MailMessage.