This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

javamail prob: can send to only one recipient...  RSS feed

Veronica Damian
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, I'm having a problem with Javamail.. I can send email only to one recipient.. if I try to send to more than one recipient I get an error..

message.setRecipient(Message.RecipientType.TO, to);
message.addRecipient(Message.RecipientType.TO, toW);

I get an error unless I remove 2nd line...

(I don't want to add both recipients in one stmt because the 2nd one will go inside a conditional; whether email gets sent to 2nd address will depend on whether user checks a checkbox in the form..)

if I use addRecipient() for both addresses, thus:

message.addRecipient(Message.RecipientType.TO, to);
message.addRecipient(Message.RecipientType.TO, toW);

I also get an error.. only way I don't get an error is if I leave only one of the two stmts..

I put everything in a try-stmt now.. so what happens now is it doesn't throw an error, but it still doesn't tell me why email doesn't get sent..

try {
InternetAddress from = new InternetAddress(sEmail, sName);
InternetAddress to = new InternetAddress(sMe);
InternetAddress toW = new InternetAddress(sMeW);
message.setRecipient(Message.RecipientType.TO, to);
// message.addRecipient(Message.RecipientType.TO, toW);
// email doesn't get sent if I leave above line..

} catch (Exception ex) { // also tried:
} catch (MessagingException ex) { // b/c this is
// exc thrown by Transport.send() method..
// in both cases I don't know why email isn't getting sent..
System.out.println("error attempting to send email");

what do I have to do to find out why email isn't getting sent?

thank you very much..
Paul Sturrock
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't say what error your applciation generates, but I'm guessing you are seeing an IllegalWriteException, which will occur "if the underlying implementation does not support modification of existing values" (a direct quore from the JavaDocs).

Why not use the method that takes an array of addresses and use your conditional logic to build the array?
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!