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
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