Email distribution lists make it possible to send emails to a group of people without writing individual email addresses. You can create a number of lists based on types of people 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 programmatically in Java.
- Java API to Create MS Outlook Distribution Lists
- Create a Distribution List in MS Outlook
- Read an MS Outlook Distribution List
Java API to Create MS Outlook Distribution Lists
Aspose.Email for Java is an amazing API to work with emails. It lets you create, send, and process emails and work with various email clients including MS Outlook. We will use this API to create and read the Outlook distribution lists in this article. You can either download the API or install it using the following Maven configurations.
Repository: <repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>http://repository.aspose.com/repo/</url> </repository> Dependency: <dependency> <groupId>com.aspose</groupId> <artifactId>aspose-email</artifactId> <version>22.3</version> <classifier>jdk16</classifier> </dependency>
Create a Distribution List in MS Outlook in Java
MS Outlook uses PST format to store the information about the distribution lists. Let’s see how to create a distribution list in MS Outlook programmatically using Aspose.Email for Java.
- 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 Java.
Read an MS Outlook Distribution List in Java
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 Java.
Get a Free API License
You can use Aspose.Email for Java 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 Java. Furthermore, you have seen how to read the Outlook distribution lists programmatically. Besides, you can explore more about the Java email API using the documentation. Also, you can post your questions or queries on our forum.