Email distribution lists make it easier to send a single email to a group of people without writing their individual email IDs. You can create as many lists as required based on the circles you have, such as official, social, etc. MS Outlook also allows you to make the distribution lists and often you may need to create such lists programmatically. So let’s see how to create and read MS Outlook distribution lists in C# .NET.
- C# API to Create MS Outlook Distribution Lists
- Create a Distribution List in MS Outlook
- Read an MS Outlook Distribution List
C# API to Create MS Outlook Distribution Lists
Aspose.Email for .NET is a feature-rich API to create, send, and process emails. Furthermore, it allows you to work with different email clients including MS Outlook. We will use this API to create and read the Outlook distribution lists. You can either download the API’s DLL or install it from NuGet using the following command.
PM> Install-Package Aspose.Email
Create a Distribution List in MS Outlook in C#
MS Outlook uses PST format to store the information about the distribution lists. Let’s see how to create an Outlook distribution list in C# using Aspose.Email for .NET.
- First, create string objects to store details of the members.
- Then, create a PST file using the PersonalStorage.Create() method to store the distribution list.
- After that, make a new folder in PST using PersonalStorage.CreatePredefinedFolder() method and set its name.
- Then, create a MapiDistributionListMember object for each member and initialize it.
- Create a new MapiDistributionListMemberCollection object and add members to it.
- Assign the collection to a MapiDistributionList object.
- Finally, add a distribution list to the folder of PST using the FolderInfo.AddMapiMessageItem() method.
The following code sample shows how to create an MS Outlook distribution list in C#.
C# Read an MS Outlook Distribution List
You can also read an Outlook distribution list and fetch the contacts’ information. The following steps show how to perform this operation.
- Load the distribution list from the PST file using MapiMessage.Load() method.
- Fetch the list using MapiMessage.ToMapiMessageItem() method and cast it to MapiDistributionList.
- Read the contacts from the MapiDistributionList object.
The following code sample shows how to read an MS Outlook distribution list in C#.
API to Create Outlook Distribution List in C# - Get a Free License
You can create Outlook distribution lists without evaluation limitations by getting a free temporary license.
A distribution list in MS Outlook lets you send an email to a group of people. In this article, you have learned how to create MS Outlook distribution lists in C#. Furthermore, you have seen how to read the Outlook distribution lists programmatically. Besides, you can explore more about .NET email API using the documentation. Also, you can post your questions or queries on our forum.