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("From@domain.com", "To@domain.com", "Message Subject", "Message Body");
mailMsg.CC.Add("R1@domain.com, R2@domain.com");
mailMsg.Bcc.Add("Bcc1@domain.com, Bcc2@domain.com");
// Add attachments
mailMsg.Attachments.Add(new Attachment("File1.pdf"));
mailMsg.Attachments.Add(new Attachment("File2.zip"));
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.
after constructing the message, can i simply send the message? like:
mailMsg.Send();
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.
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.
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);
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:
https://exchange-server-url/ews/Exchange.asmx
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;
}