dcsimg
Address Type
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Elena_Santander
Posted On:   Friday, August 30, 2002 02:11 AM

Hi,
I try to extract the addrress of all recipients for a message with tihs method.

String dir = miMessage.getRecipients(Message.RecipientType.TO).toString();

But the result isn`t the correct. I only retirve.

Ljavax.mail.internet.InternetAddress;@4b6009

Hwow can I extract the correct address???

Regards E.

Re: Address Type

Posted By:   suraj_berwal  
Posted On:   Thursday, September 5, 2002 09:55 PM


To get the correct email addresses use 
InternetAddress class and its method getAddress().

also u get an array of adresses when u use the above
method.so u have to read the array and extract
addresses from each address u get.

U can rewrite your code like this:
//obtain an array of the addresses
Address [] to = miMessage.getRecipients(Message.RecipientType.TO);

//this would give u the first email addres in the "To" header field as a string
String dir = ((InternetAddress)to[0]).getAddress();

u can use StringBuffer object to retrieve all the addresses as string from the array.
like this:

StringBuffer strBuf = new StringBuffer(((InternetAddress)to[0]).getAddress());
for (int i = 1; i < to.length; i++)
{
strBuf.append(", ").append(((InternetAddress)to[i]).getAddress());
}

I hope that would help u.

Regards
Suraj Berwal.

About | Sitemap | Contact