This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

java class not found error  RSS feed

 
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
 
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 {................}
 
"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?
 
Yes, my master! Here is the tiny ad you asked for:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!