kadamb
kadamb

Reputation: 1738

Not able to view 'To' field using java mail API

I am trying to fetch/read my email using java mail API. I am using following line to read the 'To' field

System.out.println("TO:" +  message.getRecipients(Message.RecipientType.TO));

And it is giving the following output :

TO:[Ljavax.mail.internet.InternetAddress;@6e1567f1

where as I want the output like

[email protected]

Upvotes: 1

Views: 68

Answers (2)

kiran jallepalli
kiran jallepalli

Reputation: 17

message.getRecipients(Message.RecipientType.Io)) returns an array of message.
Retrive a value from message array sample code snippet.

Address[] recipients = message.getRecipients(Message.RecipientType.TO);
for(Address address : recipients){
    System.out.println(address.toString());
}

Upvotes: 0

user1134181
user1134181

Reputation:

Try it:

Address[] recipients = message.getRecipients(Message.RecipientType.TO);
for(Address address : recipients) {
   System.out.println("TO:" +  address.toString());
}

Upvotes: 3

Related Questions