Click to See Complete Forum and Search --> : Java Servlets - Email question


sanjuT
01-25-2005, 11:26 AM
Hi All!

I am not sure what the technical name is for this, but this is what i use for sending e-mails with my java servlets:


// create some properties and get the default Session
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
Session session = Session.getDefaultInstance(props, null);

try {
// create a message
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));

InternetAddress[] address = {new InternetAddress(EmailTo)};
InternetAddress[] carbon = {new InternetAddress(from)};
InternetAddress[] carbon1 = {new InternetAddress("c@b.com")};

msg.setRecipients(Message.RecipientType.TO, address);
msg.setRecipients(Message.RecipientType.CC, carbon);
msg.addRecipients(Message.RecipientType.CC, carbon1);

msg.setSubject("SubjectTitle");
msg.setSentDate(new Date());
// create and fill the first message part

msg.setText(msgText1);

Transport.send(msg);
} catch (MessagingException mex) {
mex.printStackTrace();
Exception ex = null;
if ((ex = mex.getNextException()) != null) {
ex.printStackTrace();
}
}



Now i have a form where i havecheckboxes to give the users the choice where to submit the form data.

this code doesn't seem to work when more than one e-mail address is contained in the variable 'EmailTo'.

I have asp pages where i use CDONTS and it is possible to have more than one e-mail address contained in the variable used to specify e-mails. I guess this is not possible in Java Servlets?

Is there a way around this? would i need to have an 'if' statement everytime i want to add a CC?

any help is appreciated!

THANKS!:D

sanjuT
01-25-2005, 01:37 PM
don't worry, i figured it out!

i put a loop or each choice the user makes (it has to be radio buttons).

so if they choose the 2nd radio button, a loop runs specificaly for those emails.

hadef
01-27-2005, 11:19 PM
for long time i wanted to know how to send mail with java (i know i should check the documentation )
so could u please post the complete code with more explainatoin please....

thanks