I have this code
Address[] from = message.getFrom();
System.out.println(from[0]);
Which prints: AuthorName <name@domain>
or name@domain
- depends by the mail.
How I can get just name@domain
all the time, without AuthorName
?
Address is abstract, and the Javadoc points to two derived classes, one for news and the other with the not too helpful name InternetAddress
(guess news wasn't on the internet back then).
In this case you probably get an InternetAddress
, which has getAddress method which seems to do what you want. So cast the returned address to InternetAddress
and get the email address:
Address[] from = message.getFrom();
InternetAddress ia = (InternetAddress) from[0];
System.out.println(ia.getAddress());