Create a msg file straightaway

Hi there,

Is it possible to create a msg file straightaway with message information and attachments via Aspose.Email?

for example:

setTo("recp1"); //more than two recps



setCc("recp"); // more than two recp




setBody("htmle message");

addattach("attachment1.doc"); //more than two attachments




saveasMsg("c:\sample.msg"); //save as a msg file straightaway without retrieving message from email server

Hi Hal,

Thank you for considering Aspose.Email.

I am glad to share with you that Aspose.Email fulfills all your requirements of:

  • Creating new message from scratch
  • Adding sender as well recepients information to it
  • Setting message subject as well as body
  • Adding attachments to the message
  • Saving the message as MSG, EML, EMLX or MHTML

Sample Code:

MailMessage mailMsg = new MailMessage("", "", "Message Subject", "Message Body");


// Add attachments
mailMsg.Attachments.Add(new Attachment("File1.pdf"));
mailMsg.Attachments.Add(new Attachment(""));
mailMsg.Attachments.Add(new Attachment("File3.txt"));

// Now save the message as:

// MSG
mailMsg.Save("Message.msg", MailMessageSaveType.OutlookMessageFormat);

// or EML
mailMsg.Save("Message.eml", MailMessageSaveType.EmlFormat);

// or MHTML
mailMsg.Save("Message.mhtml", MailMessageSaveType.MHtmlFormat);

You can further refer to our online Programmer’s Guide for more examples on using Aspose.Email. Please let us know if we can of any additional help to you.

Thanks, Kashif.

after constructing the message, can i simply send the message? like:


some questions:

is it possible i send this message via the exchange server, and retrieve the message from the exchange server in order to archive it in msg format? how can i simply retrieve the message (such as by a unique code)? any sample code available?

my idea is to send message via the exchange server (not smtp/pop, but MAPI) and archive the message in msg format either straightaway or from exchange/outlook.

Hi Hal,

Yes, you can achieve this using Aspose.Email API. Please refer to the online documentation articles Send Email Message using Exchange Server and Save Message from Exchange Server for your kind reference. If you are dealing with Exchange Server 2010, you will have to use the code example of ExchangeWebServerClient. With Exchange Server 2007, you can use both the ExchangeClient as well as ExchangeWebServiceClient.

For further examples, please refer to the section Programming with Exchange Server. In case you feel any difficulty, please feel free to write us back. We’ll be glad to assist you further.

hi Kishf,

i tested the ExchangeWebServiceClient, but failed :

The request failed with the error message:


Object moved

are you able to give some ideas about the error?

BTW, i tested EWS well with MS managed EWS API.


Hi Hal,

Could you please share your sample code with us that gives rise to this error? At my end, I have tested the following code with Exchange Server 2010 and it returns the Mailbox information without any error.

Sample Code:

ExchangeWebServiceClient client = GetAsposeEWSClient();

// Get mailbox size
Console.WriteLine("Mailbox size: " + client.GetMailboxSize() + " bytes");

// Get exchange mailbox info
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo();

// Get Mailbox URI
Console.WriteLine("Mailbox URI: " + mailboxInfo.MailboxUri);

// Get Inbox folder URI
Console.WriteLine("Inbox folder URI: " + mailboxInfo.InboxUri);

// Get Sent Items folder URI
Console.WriteLine("Sent Items URI: " + mailboxInfo.SentItemsUri);

// Get Drafts folder URI
Console.WriteLine("Drafts folder URI: " + mailboxInfo.DraftsUri);

hi kashif,

My code is like below


ExchangeWebServiceClient client = new ExchangeWebServiceClient("", "cc", "cc", "");

// Create instance of type MailMessage
MailMessage msg = new MailMessage();
msg.From = "";
msg.To = "";
msg.Subject = "Sending message from exchange server";
msg.HtmlBody = "Object moved

sending message from exchange server
//msg.Body = "kkkkk";
// Send the message

in your code, how do you initiate:

ExchangeWebServiceClient client = GetAsposeEWSClient();

BTW. I have to use a local domain with ExchangeServer2010 (no SMTP and POP or IMAP support, only MAPI/EWS support)


ExchangeWebServiceClient client = new ExchangeWebServiceClient("cc.local", "dd", "ddd", "cc.local");
//ExchangeWebServiceClient client = GetAsposeEWSClient();\

// Get mailbox size
Console.WriteLine("Mailbox size: " + client.GetMailboxSize() + " bytes");
// Get exchange mailbox info
ExchangeMailboxInfo mailboxInfo = client.GetMailboxInfo();

this code doesn’t work.

Hi Hal,

It seems that you are not setting the EWS Url properly while initiating the ExchangeWebServiceClient. Please have a look at the article How to get your EWS connection settings to know your EWS settings. The EWS url is always of the form:


Once you are able to get this URL, you can check its validity via your web browser. It should you username and password. Please use this URL in your application then.

At my end, the GetAsposeEWSClient funciton is local to my application where I initialize the account info to my Exchange account and the code is as follow. Please let us know if we can be of any additional help to you.

Sample Code:

private static ExchangeWebServiceClient GetAsposeEWSClient()
    const string mailboxUri = "https://exchange-server-url/ews/Exchange.asmx";
    const string domain = @"";
    const string username = @"username";
    const string password = @"password";
    NetworkCredential credential = new NetworkCredential(username, password, domain);
    ExchangeWebServiceClient client = new ExchangeWebServiceClient(mailboxUri, credential);

    // Return the instance of ExchangeWebServiceClient class
    return client;