0
votes

I am trying to use JavaMail API. i have downloaded javamail 1.4 and jaf1.1.1 . i have changed classpath variable to

C:\Program Files (x86)\jaf-1_1_1\jaf-1.1.1\activation.jar;C:\Program Files (x86)\javamail->1_4\javam ail-1.4\mail.jar

I copied a program from net which will send a mail to my gmail

// File Name SendEmail.java

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendEmail
{
   public static void main(String [] args)
   {    
      // Recipient's email ID needs to be mentioned.
      String to = "[email protected]";

      // Sender's email ID needs to be mentioned
      String from = "[email protected]";

      // Assuming you are sending email from localhost
      String host = "localhost";

      // Get system properties
      Properties properties = System.getProperties();

      // Setup mail server
      properties.setProperty("mail.smtp.host", host);

      // Get the default Session object.
      Session session = Session.getDefaultInstance(properties);

      try{
         // Create a default MimeMessage object.
         MimeMessage message = new MimeMessage(session);

         // Set From: header field of the header.
         message.setFrom(new InternetAddress(from));

         // Set To: header field of the header.
         message.addRecipient(Message.RecipientType.TO,
                                  new InternetAddress(to));

         // Set Subject: header field
         message.setSubject("This is the Subject Line!");

         // Now set the actual message
         message.setText("This is actual message");

         // Send message
         Transport.send(message);
         System.out.println("Sent message successfully....");
      }catch (MessagingException mex) {
         mex.printStackTrace();
      }
   }
}

This is getting compiled properly but it gives me a runtime error saying

could not find or load main class SendEmail

i have given proper file name and i am sure i have run it using java SendEmail

Not only this program , all other simple java programs are also giving me the same error.

But if i delete my classpath variable ,then all other programs are working fine.

1

1 Answers

1
votes

you need to set path to the class file which gets generated after compiling your java file.

suppose your file is in D:\ you can set class path to that like following

set CLASSPATH="D:\"

which will help java to find your class file present under that path.