• Post Reply Bookmark Topic Watch Topic
  • New Topic

java class not found error  RSS feed

Lokachari Paidakula
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 = "name1@address1.com";
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("mail.smtp.host", 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
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are you sure you can use like this:
....main() throws Exception {................}
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you put mail.jar in the lib/ext directory?
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!