| | |
About How to run JavaMail programs??
![]() |
•
•
Join Date: Apr 2008
Posts: 293
Reputation:
Solved Threads: 11
Java Syntax (Toggle Plain Text)
import java.util.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; // Send a simple, single part, text/plain e-mail public class TestEmail { public static void main(String[] args) { // SUBSTITUTE YOUR EMAIL ADDRESSES HERE!!! String to = "vipan@vipan.com"; String from = "vipan@vipan.com"; // SUBSTITUTE YOUR ISP'S MAIL SERVER HERE!!! String host = "smtp.yourisp.net"; // Create properties, get Session Properties props = new Properties(); // If using static Transport.send(), // need to specify which host to send it to props.put("mail.smtp.host", host); // To see what is going on behind the scene props.put("mail.debug", "true"); Session session = Session.getInstance(props); try { // Instantiatee a message Message msg = new MimeMessage(session); //Set message attributes msg.setFrom(new InternetAddress(from)); InternetAddress[] address = {new InternetAddress(to)}; msg.setRecipients(Message.RecipientType.TO, address); msg.setSubject("Test E-Mail through Java"); msg.setSentDate(new Date()); // Set message content msg.setText("This is a test of sending a " + "plain text e-mail through Java.\n" + "Here is line 2."); //Send the message Transport.send(msg); } catch (MessagingException mex) { // Prints all nested (chained) exceptions as well mex.printStackTrace(); } } }//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 ??
![]() |
Other Threads in the Java Forum
- Previous Thread: Problem with loop, infinite or no loop at all
- Next Thread: IBM On-Demand Host Entry 3.0 Issues. .
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working





