Email Java fails get Original Email Addresss

SampleFile.zip (5.8 KB)

Aspose Team,
We use the Aspose Email java package to get email addresses, and found out that it fails to get the original address for some msg file.

Following is the sample code and attached is a sample file.
The operating system is Ubuntu 20.04. Java version is 17. Aspose Email java packages are 22.6 and 23.9.

Note that with version 22.6 we used the getFrom method to get MailAddress, and we use the method getSender to get MailAddress with version 23.9 because you fixed an issue with the From and Sender MIME headers (23.5 Aspose.Email version) (see Aspose Email From value has changed with java version upgrade - #6 by jmuth).

import com.aspose.email.*;

public class EmailAddress_25 {

public static void main(String[] args) {

    try {
        new com.aspose.pdf.License().setLicense("/home/ubuntu/QmulusWorker/required/Aspose.Total.Java.lic");
        String path = "/home/ubuntu/testdirs/emailaddress_25/RIJ.PC.00000003.msg";

        MsgLoadOptions mlo = new MsgLoadOptions();
        mlo.setKeepOriginalEmailAddresses(false);
        MailMessage mailMessage = MailMessage.load(path, mlo);

        MailAddress mailAddress = mailMessage.getSender();  // for 23.9
        // MailAddress mailAddress = mailMessage.getFrom();  // for 22.6
        String displayName =  mailAddress.getDisplayName();
        String address =  mailAddress.getAddress();
        String originalAddress =  mailAddress.getOriginalAddressString();
        System.out.println("displayName = " + displayName);
        System.out.println("address = " + address);
        System.out.println("originalAddress = " + originalAddress);

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

}

Following is the result with version 22.6:
displayName = Cyndy Foulkrod
address =
originalAddress = /O=INRS/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=CFOULKRO

And following is the result with version 23.9:
displayName = Cyndy Foulkrod
address =
originalAddress =

Hello @xyang,

We’ll contact you as soon as check this.
Thanks.

Hello @xyang,

The Aspose API uses the PidTagSentRepresentingEmailAddress and PidTagSenderEmailAddress MAPI properties to set MIME “From” and “Sender” headers during conversion.
The “From” header is assigned from the PidTagSentRepresentingEmailAddress property if it has been set. If the property is not set, the PidTagSenderEmailAddress property will be used.
The “Sender” header is always assigned from the PidTagSenderEmailAddress property.

In the case of an “EX” address format, the PidTagSentRepresentingName/PidTagSenderName properties will be used to idetify the “From” and “Sender” headers.

PidTagSentRepresentingName (From header)
Cyndy Foulkrod </O=INRS/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=CFOULKRO>

PidTagSenderName (Sender header)
Cyndy Foulkrod

In MIME format:

The “From” header is used to identify the person who is sending the email. It should contain the email address of the person you are sending the email on behalf of.
The “Sender” header is used to identify the software that is sending the email. It is typically used by email servers to track the origin of an email.

In the context of Microsoft Outlook and Exchange Server, both PidTagSentRepresentingEmailAddress and PidTagSenderEmailAddress are properties related to email messages, specifically dealing with sender information. Here’s the difference between the two:

PidTagSentRepresentingEmailAddress:

This property represents the email address of the actual sender who sent the email. It is used to indicate the email address of the person or entity who physically sent the message.
For example, if a secretary sends an email on behalf of their manager, the PidTagSentRepresentingEmailAddress property would contain the manager’s email address, indicating that the manager is the actual sender, even though the email was sent by the secretary.

PidTagSenderEmailAddress:

This property represents the email address of the entity or person who appears as the sender of the email. It is used to display the sender’s information in the email client.
Using the previous example, if a secretary sends an email on behalf of their manager, the PidTagSenderEmailAddress property would contain the secretary’s email address because the email client displays the secretary as the sender, even though the actual sender is the manager (indicated by the PidTagSentRepresentingEmailAddress property).

PidTagSentRepresentingEmailAddress documentation
PidTagSentRepresentingEmailAddress Canonical Property | Microsoft Learn

The outgoing transport provider must always leave these properties unchanged if it has been set by the sending client. If it is unset, the transport provider should set it to the PR_SENDER_EMAIL_ADDRESS (PidTagSenderEmailAddress) property on the outbound copy of the message, and leave it unset on the local copy.

Hello @sergey.vivsiuk,

Thank you very much for the explanation about how Aspose API gets the values for From and Sender. However, our problem is that we currently use getSender (instead of getFrom with 22.6) to get MailAddress with version 23.9 because you fixed an issue with the From and Sender MIME headers (23.5 Aspose.Email version) (see Aspose Email From value has changed with java version upgrade), and getSender does not get the original address for the sample file.

Because we can still get the original address with method getFrom with version 23.9, we can probably use getFrom to get the original address if getSender does not get it.

Hello @xyang,

You can use both properties to get the address.