on 02-09-2009 2:10 PM
Hi All,
i have created a background callable object to send mails where I am using following code :-
import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public boolean postMail(String[] p_to,
String[] p_cc,
String[] p_bcc,
String p_subject,
String p_from,
String p_message) {
try{
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "<portal smtp host ip>");
Session session = Session.getDefaultInstance(props);
// create a message
Message msg = new MimeMessage(session, null);
// set "From"
InternetAddress addressFrom = new InternetAddress(p_from);
msg.setFrom(addressFrom);
//Set "To"
InternetAddress[] addressTo = new InternetAddress[p_to.length];
for (int i = 0; i < p_to.length; i++) {
addressTo<i> = new InternetAddress(p_to<i>);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
//Set "CC"
InternetAddress[] addressCC = new InternetAddress[p_cc.length];
for (int i = 0; i < p_cc.length; i++) {
addressCC<i> = new InternetAddress(p_cc<i>);
}
msg.setRecipients(Message.RecipientType.CC, addressCC);
//Set "BCC"
InternetAddress[] addressBCC = new InternetAddress[p_bcc.length];
for (int i = 0; i < p_bcc.length; i++) {
addressBCC<i> = new InternetAddress(p_bcc<i>);
}
msg.setRecipients(Message.RecipientType.BCC, addressBCC);
//Set the "Subject"
msg.setSubject(p_subject);
//Set Message and Message Type
msg.setContent(p_message, "text/plain");
//Send mail over the SMTP
Transport.send(msg);
}catch (Exception e) {
// TODO: handle exception
}
return false;
}
But when i am executing this CO, I get java.lang.NoClassDefFoundError for javax.mail.Message.
Can anybody help me with this?
Thanks and regards,
Amey Mogare
Hi Amey,
i guess the solution was the missing reference ?
What do you have to use for the mail jar ?
Regards,
Kai
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually, mail.jar, activation.jar were not deployed on server...I only created and added compilation public part of this external library DC. But later I figured this out and created-n-added assembly public part to a J2E server component Library DC and deployed it.
Then it worked successfully.
Thanks and regards,
Amey Mogare
User | Count |
---|---|
81 | |
24 | |
11 | |
9 | |
7 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.