Extract Original Email Address

I am extracting MSG file from a PST file, and before saving each MSG to disk I am trying to obtain various metadata about the message to put in a database. This is mostly working fine, but one critical thing is that I get the actual email address of each recipient of the email. the getDisplayTo() function sometimes shows jsut the person name instead of their email address. I have studied the documentation and cannot find a way to discover the original email address. Can you help?

Hello @NeilBradley ,

Thank you for reporting your issue.

To get the recipients’ email addresses, please use the recipientCollection. Try the following code sample:

// Get the collection of recipients
MapiRecipientCollection recipientCollection = mapiMessage.getRecipients();

// Build a comma-separated string of recipient addresses
StringBuilder recipientAddresses = new StringBuilder();

for (int i = 0; i < recipientCollection.size(); i++) {
    String recipientAddress = recipientCollection.get(i).getEmailAddress();

    // Append the recipient address to the string
    recipientAddresses.append(recipientAddress);

    // Append a comma if there are more recipients
    if (i < recipientCollection.size() - 1) {
        recipientAddresses.append(", ");
    }

Thanks so much. I got it working once I changed get() to get_Item().

But is it possible for me to determine which of the recipients were in the To: list, and which in the BC: and BCC: list?

Neil.

@NeilBradley ,

Please use MapiRecipient.getRecipientType(). It returns MapiRecipientType. And share your feedback.