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