Skip to Main Content

Java User Groups


For appeals, questions and feedback, please email

Query the value of CC: using Javax.mail (not really working)

Max SteinerNov 9 2020

Hi all,
I have an Exchange Mailbox with an email alias configured. So, when somebody send a mail to the email alias I should be able to get it with my java code to process it. The problem is the recipient id is allways populated with the root mailbox address and not with the alias previously setup.
The code to check the received mails is the following:
--------------------Java Code-----------------------
public void checkMailsTest(Store connStore, String mailAddress) throws MessagingException{
Folder folderInbox = connStore.getFolder("INBOX");;
Message[] foundMessages = FlagTerm(new Flags(Flags.Flag.SEEN), false));"checkMailsTest() unread e-mails found: {}", foundMessages.length);
for (int i = 0; i < foundMessages.length; i++) {
MimeMessage miMsg = (MimeMessage) foundMessages[i];
Enumeration headers = miMsg.getAllHeaders();
Header header = (Header) headers.nextElement();
System.out.println(header.getName() + " : " + header.getValue());
----------------------End Code------------------------

Now, with the following code, I'm reading the messages and getting the header fields. So when I check the CC field is coming with the value of the mailbox name but not with the alias name. Nevertheless, if I check the message details in exchange mail application, the CC value is populated with the alias name (as it should be)

Any idea how can I get the correct CC value?
Thanks a lot in advance

Post Details
Added on Nov 9 2020