Question : Test javamail through command line

I tried to test javamail through command line (code sampe is from this site: http://www.vipan.com/htdocs/javamail.html).

Compile the code is successful:
javac  -classpath jar/mail.jar:jar/activation.jar:jar/mailapi.jar TestEmail.java

But when I run the code, there is error:
java TestEmail

Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
Could not find the main class: TestEmail2.  Program will exit.

Is there a way to test javamail through command line without using a servlet? Thanks!

Codes attached:

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 = "[email protected]";
        String from = "[email protected]";
        // 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

Answer : Test javamail through command line

It's interesting, it's showing that you are using a single processor HAL already. I'm not entirely sure why this isn't handling the locks correctly but lets replace it with the Uniprocessor HAL anyways.

Okay, navigate to c:\winnt\system32 and rename ntoskrnl.exe to ntoskrnl.exe.old just to be safe.

Then copy halapic.dll and ntoskrnl.exe to c:\winnt\system32.

Change the boot.ini from:

multi(0)disk(0)rdisk(0)partition(2)\WINNT="Windows NT Server Version 4.00" /HAL=hal.dll /KERNEL=ntoskrnl.exe /NUMPROC=1

to

multi(0)disk(0)rdisk(0)partition(2)\WINNT="Windows NT Server Version 4.00" /HAL=halapic.dll /KERNEL=ntoskrnl.exe /NUMPROC=1

Try booting this and see if that makes it any better. Remember to change the vCPUs back to 1 and the OS back to Win NT 4 in vCenter.
Random Solutions  
 
programming4us programming4us