• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java class not found error

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are you sure you can use like this:
....main() throws Exception {................}
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you put mail.jar in the lib/ext directory?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic