File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes java class not found error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "java class not found error" Watch "java class not found error" New topic

java class not found error

Lokachari Paidakula

Joined: Nov 16, 2001
Posts: 7
My actual error message is:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Address
Here is my code:
import java.util.Properties;
import java.util.Date;
import java.text.DateFormat;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class sendMailWithAttachment {
public static void main (String args[])
throws Exception {
// String host = args[0]; String from = args[1]; String to = args[2]; String fileAttachment = args[3];
// host and from are customized to amat.
String host = "hostname";
String from = "";
String fileAttachment = args[0];
InternetAddress allToAddress[] = InternetAddress.parse(args[1]); //comma seperated email addressess
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("", host);
// Get session
Session session = Session.getInstance(props, null);
// Get current date in the format "Feb 26, 2003"
Date now = new Date();
DateFormat df = DateFormat.getDateInstance();
String currentDate = df.format(now);
// Define message
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipients(Message.RecipientType.TO, allToAddress);
String subjectText = "2x4 User Account Status as of " + currentDate;
// create the message part
MimeBodyPart messageBodyPart = new MimeBodyPart();
// Fill message
String bodyText = new String();
bodyText = "Hi,\n\n";
bodyText = bodyText + "DO NOT REPLY to this message. This is an automated message.\n";
bodyText = bodyText + "Please find attached DDVvault user Account Status File as of " + currentDate +".\n\n";
bodyText = bodyText + "Regards\n2x4 Support Team\n";
Multipart multipart = new MimeMultipart();
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(fileAttachment);
messageBodyPart.setDataHandler(new DataHandler(source));
// Put parts in message
// Send the message
Transport.send( message );
do i need to have activation.jar and mail.jar file for this... if yes, where will i get this
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
are you sure you can use like this:
....main() throws Exception {................}
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Did you put mail.jar in the lib/ext directory?

"JavaRanch, where the deer and the Certified play" - David O'Meara
It is sorta covered in the JavaRanch Style Guide.
subject: java class not found error
It's not a secret anymore!