About How to run JavaMail programs??

Reply

Join Date: Apr 2008
Posts: 293
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

About How to run JavaMail programs??

 
0
  #1
Jul 30th, 2008
  1. import java.util.*;
  2. import javax.mail.*;
  3. import javax.mail.internet.*;
  4. import javax.activation.*;
  5.  
  6. // Send a simple, single part, text/plain e-mail
  7. public class TestEmail {
  8.  
  9. public static void main(String[] args) {
  10.  
  11. // SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!!
  12. String to = "vipan@vipan.com";
  13. String from = "vipan@vipan.com";
  14. // SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!!
  15. String host = "smtp.yourisp.net";
  16.  
  17. // Create properties, get Session
  18. Properties props = new Properties();
  19.  
  20. // If using static Transport.send(),
  21. // need to specify which host to send it to
  22. props.put("mail.smtp.host", host);
  23. // To see what is going on behind the scene
  24. props.put("mail.debug", "true");
  25. Session session = Session.getInstance(props);
  26.  
  27. try {
  28. // Instantiatee a message
  29. Message msg = new MimeMessage(session);
  30.  
  31. //Set message attributes
  32. msg.setFrom(new InternetAddress(from));
  33. InternetAddress[] address = {new InternetAddress(to)};
  34. msg.setRecipients(Message.RecipientType.TO, address);
  35. msg.setSubject("Test E-Mail through Java");
  36. msg.setSentDate(new Date());
  37.  
  38. // Set message content
  39. msg.setText("This is a test of sending a " +
  40. "plain text e-mail through Java.\n" +
  41. "Here is line 2.");
  42.  
  43. //Send the message
  44. Transport.send(msg);
  45. }
  46. catch (MessagingException mex) {
  47. // Prints all nested (chained) exceptions as well
  48. mex.printStackTrace();
  49. }
  50. }
  51. }//End of class

I new to java mail...I m downloading javaApI and jaf..and set classpath for mail.jar and activation.jar..

I compile java file
C:\Program Files\Java\jdk1.6.0_02\bin>javac -classpath mail.jar;activation.jar TestEmail.java

But I want to know How to run this file???
It gives error
C:\Program Files\Java\jdk1.6.0_02\bin>java TestEmail.java
Exception in thread "main" java.lang.NoClassDefFoundError: TestEmail/java

C:\Program Files\Java\jdk1.6.0_02\bin>java TestEmail
Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingE
xception

How to run this ??
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC