Multiple Email Messages

I am writing a web application that sends an email based on form data, and I want the user to be able to enter any number of email addresses into the form. My code is working to send out single email messages. However, I don't know how to send multiple email addresses at once. I think the problem is that I don't know how to format multiple "to" addresses.

For example:

String to_address ="foo@bar.com";// sends a single email message

String to_address ="foo@bar.com, hello@world.com";// fails

String to_address ="foo@bar.com; hello@world.com";// fails

I can duplicate the functionality by parsing the to_address input into an ArrayList and calling the code to send the email in a for loop that sends the emails separately to each of the elements (email addresses) in the ArrayList, but if I knew how to format the email addresses that would be more elegant.

[1072 byte] By [DavidKerka] at [2007-11-26 17:38:53]
# 1

I do not think you need do a loop. You can use the parse function of InternetAddress to parse the string and get you the list of the addresses. Do you try the following? Did it work for you?

msg.setRecipients(Message.RecipientType.TO,

InternetAddress.parse(to, false));

http://java.sun.com/j2ee/1.4/docs/api/javax/mail/internet/InternetAddress.html#parse(java.lang.String,%20boolean)

satishva at 2007-7-9 0:07:03 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

try

{

SmtpClient client = new SmtpClient(mailServer);//orginal smtp

client.from(from_address);

client.to(to_address);

PrintStream message = client.startMessage();

message.println(messageText);

client.closeServer();

}

catch (IOException e)

{

System.out.println("ERROR SENDING EMAIL:"+e);

}

Where would I insert that into this code?

DavidKerka at 2007-7-9 0:07:03 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
You don't seem to be using JavaMail at all. I think you're using the old,non-standard, deprecated sun.* API.
bshannona at 2007-7-9 0:07:03 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...