Meaningless Drivel is fun!*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 19651
    
  18

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: 18541
    
    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);
 
 
subject: javamail with to: list repeated
 
Similar Threads
Can i send mail to other than Local Address with this code..i mean to Yahoo or Gmail
How to send mail using JavaMail API?
JavaMail works on one server, but not another
illlegal address exception.
multiple recipients