aspose-email-for-.NET

We are pleased to announce the release of Aspose.Email for .NET 18.5. This month’s release introduces several new features related to various API functionality. It also enhances the API by fixing several bugs that were reported by our valued customers with the previous version of the API. For a detailed note on what is new and fixed, please visit the release notes section of Aspose.Email API.

Auto Discover Exchange Server in C#

This release introduces a new feature of auto-discovery of Exchange server settings using the account’s user name and password. The AutoDiscoverService introduced by the API gets this information from the exchange server using the username and password specified by the application user. In addition to other settings returned by the API, you can get the server’s EWS Url as well using this feature.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET
string email = "asposeemail.test3@aspose.com";
string password = "Aspose@2017";
AutodiscoverService svc = new AutodiscoverService();
svc.Credentials = new NetworkCredential(email, password);
IDictionary<UserSettingName, object> userSettings = svc.GetUserSettings(email, UserSettingName.ExternalEwsUrl).Settings;
string ewsUrl = (string)userSettings[UserSettingName.ExternalEwsUrl];
Console.WriteLine("Auto discovered EWS Url: " + ewsUrl);

Abort PST to Exchange Server Operation

PST restore feature of the Aspose.Email API lets you restore the contents of a PST file to Exchange server. The feature is useful in a variety of ways. There is the possibility that operation may take a long time due to the large size of the PST file. This new release of API lets you abort PST restoration process to the Exchange server based on defined time. This allows users to abort the PST restore operation in case it is taking too long to complete the operation.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET
using (IEWSClient client = EWSClient.GetEWSClient("https://exchange.office365.com/ews/exchange.asmx", "username", "password"))
{
DateTime startTime = DateTime.Now;
TimeSpan maxRestoreTime = TimeSpan.FromSeconds(15);
int processedItems = 0;
BeforeItemCallback callback = delegate
{
if (DateTime.Now >= startTime.Add(maxRestoreTime))
{
throw new CustomAbortRestoreException();
}
processedItems++;
};
try
{
//create a test pst and add some test messages to it
var pst = PersonalStorage.Create(new MemoryStream(), FileFormatVersion.Unicode);
var folder = pst.RootFolder.AddSubFolder("My test folder");
for (int i = 0; i < 20; i++)
{
var message = new MapiMessage("from@gmail.com", "to@gmail.com", "subj", new string('a', 10000));
folder.AddMessage(message);
}
//now restore the PST with callback
client.Restore(pst, new Aspose.Email.Clients.Exchange.WebService.RestoreSettings
{
BeforeItemCallback = callback
});
Console.WriteLine("Success!");
}
catch (CustomAbortRestoreException)
{
Console.WriteLine($"Timeout! {processedItems}");
}

Writing Multiple Events to ICS

Aspose.Email already lets you read multiple events from ICS file. This new release of API lets you write multiple calendar events to a single ICS file as shown in the following code sample.

// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-.NET
IcsSaveOptions saveOptions = new IcsSaveOptions();
saveOptions.Action = AppointmentAction.Create;
using (CalendarWriter writer = new CalendarWriter(dataDir + "WriteMultipleEventsToICS_out.ics", saveOptions))
{
for (int i = 0; i < 10; i++)
{
Appointment app = new Appointment(string.Empty, DateTime.Now, DateTime.Now, "sender@domain.com", "receiver@domain.com");
app.Description = "Test body " + i;
app.Summary = "Test summary:" + i;
writer.Write(app);
}
}

API Resources

The following API resources can be of help to you in getting started with Aspose.Email API.