aspose file tools*
The moose likes Java in General and the fly likes javamail with to: list repeated Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "javamail with to: list repeated" Watch "javamail with to: list repeated" New topic
Author

javamail with to: list repeated

sarvan kumar
Ranch Hand

Joined: Jul 28, 2010
Posts: 66
Hi..
I am working on java mail, in which a mail has to be sent to many recipients, mail is sending to all recipients
correctly, but To address list of the multiple recipients are repeated twice in To: address of the ms-outlook.
when i restart the jboss server then To address list of the multiple recipients are not repeated. please give some tips to get the solution


i am using ms-outlook 2003, mail.jar , activation.jar , jboss server 4.2.0

i am using the following code:

ArrayList maillist = new ArrayList();
consider mailist contains 15 email addresses
InternetAddress[] mail_address_TO = new InternetAddress[maillist.size()];
for (int i = 0; i < maillist.size(); i++) {
mail_address_TO[i] = new InternetAddress((String) maillist.get(i));
}
message.addRecipients(Message.RecipientType.TO,mail_address_TO);

Thanks in advance,
K.Saravanan
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

You're adding to the recipients list; anything that was there will remain there. Replace addRecipients with setRecipients to overwrite it.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
sarvan kumar
Ranch Hand

Joined: Jul 28, 2010
Posts: 66
Thanks Rob, for your reply, i tried with setRecipients also but still i am facing the same issue
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

You didn't post the part of your code where you sent the message, presumably adding the recipient list a second time.
sarvan kumar
Ranch Hand

Joined: Jul 28, 2010
Posts: 66
I have used the following code:

ArrayList maillist = new ArrayList();
// consider mailist contains 15 email addresses

InternetAddress[] mail_address_TO = new InternetAddress[maillist.size()];
for (int i = 0; i < maillist.size(); i++) {
mail_address_TO[i] = new InternetAddress((String) maillist.get(i));
}

message.setRecipients(Message.RecipientType.TO,mail_address_TO);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javamail with to: list repeated