Skip to Content

NoClassDefFoundError for javax.mail.Message while posting mail

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Posted on Feb 24, 2009 at 08:56 AM

    Hi Amey,

    i guess the solution was the missing reference ?

    What do you have to use for the mail jar ?

    Regards,

    Kai

    Add a comment
    10|10000 characters needed characters exceeded

    • 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

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.