Read the complete article on how to create and read MS Outlook distribution lists in C#: https://blog.aspose.com/2022/04/06/create-ms-outlook-distribution-lists-in-csharp-net/
Last active
May 9, 2022 14:40
-
-
Save aspose-com-gists/736ed7a3971410f00d272e3e04e606f1 to your computer and use it in GitHub Desktop.
Create and Read MS Outlook Distribution Lists in C# .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string displayName1 = "Sebastian Wright"; | |
string email1 = "SebastianWright@dayrep.com"; | |
string displayName2 = "Wichert Kroos"; | |
string email2 = "WichertKroos@teleworm.us"; | |
string strEntryId1; | |
string strEntryId2; | |
// Create distribution list from contacts | |
using (PersonalStorage personalStorage = PersonalStorage.Create("list.pst", FileFormatVersion.Unicode)) | |
{ | |
// Add the contact folder to PST | |
Aspose.Email.Storage.Pst.FolderInfo contactFolder = personalStorage.CreatePredefinedFolder("Contacts", StandardIpmFolder.Contacts); | |
// Create contacts | |
strEntryId1 = contactFolder.AddMapiMessageItem(new MapiContact(displayName1, email1)); | |
strEntryId2 = contactFolder.AddMapiMessageItem(new MapiContact(displayName2, email2)); | |
// Create a collection to keep members | |
MapiDistributionListMember member1 = new MapiDistributionListMember(displayName1, email1); | |
member1.EntryIdType = MapiDistributionListEntryIdType.Contact; | |
member1.EntryId = Convert.FromBase64String(strEntryId1); | |
MapiDistributionListMember member2 = new MapiDistributionListMember(displayName2, email2); | |
member2.EntryIdType = MapiDistributionListEntryIdType.Contact; | |
member2.EntryId = Convert.FromBase64String(strEntryId1); | |
// Add members to collection | |
MapiDistributionListMemberCollection members = new MapiDistributionListMemberCollection(); | |
members.Add(member1); | |
members.Add(member2); | |
// Create list | |
MapiDistributionList distributionList = new MapiDistributionList("Contact list", members); | |
distributionList.Body = "Distribution List Body"; | |
distributionList.Subject = "Sample Distribution List using Aspose.Email"; | |
// Add distribution list to PST | |
contactFolder.AddMapiMessageItem(distributionList); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load PST file | |
MapiMessage message = MapiMessage.Load("list.pst"); | |
// Fetch distribution list | |
MapiDistributionList dlist = (MapiDistributionList)message.ToMapiMessageItem(); | |
// Get members collection | |
MapiDistributionListMemberCollection members = dlist.Members; | |
// Read each MapiDistributionListMember from collection | |
MapiDistributionListMember member1 = members[0]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment