Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java class not found error

 
Lokachari Paidakula
Greenhorn
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;
message.setSubject(subjectText);
// 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";
messageBodyPart.setText(bodyText);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(fileAttachment);
messageBodyPart.setDataHandler(new DataHandler(source));
messageBodyPart.setFileName(fileAttachment);
multipart.addBodyPart(messageBodyPart);
// Put parts in message
message.setContent(multipart);
// 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"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you put mail.jar in the lib/ext directory?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic