cancel
Showing results for 
Search instead for 
Did you mean: 

NoClassDefFoundError for javax.mail.Message while posting mail

Amey-Mogare
Contributor
0 Kudos

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

Accepted Solutions (0)

Answers (1)

Answers (1)

kai_unewisse3
Active Contributor
0 Kudos

Hi Amey,

i guess the solution was the missing reference ?

What do you have to use for the mail jar ?

Regards,

Kai

Amey-Mogare
Contributor
0 Kudos

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