1

I built my code successfully and then I had a problem.

This is my code:

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

public class launcher {
    public static void main(String[] args){

      final String username = "my-email@yandex.ru";
      final String password = "my-password";

      String to = "to-email@mail.ru";

      String from = "from-email@yandex.ru";

      String host = "localhost";

      Properties properties = System.getProperties();
      properties.put("mail.smtp.auth", "true");
      properties.put("mail.smtp.starttls.enable", "true");
      properties.put("mail.smtp.host", host);

      Session session = Session.getInstance(properties);

      try{

         MimeMessage message = new MimeMessage(session);

         message.setFrom(new InternetAddress(from));

         message.addRecipient(Message.RecipientType.TO,
                                  new InternetAddress(to));

         message.setSubject("This is the Subject Line!");

         message.setText("This is actual message");

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


There is an error at this line:
Session session = Session.getInstance(properties);

This is an output message:

run:
    Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/MailLogger
    at javax.mail.Session.initLogger(Session.java:227)
    at javax.mail.Session.<init>(Session.java:212)
    at javax.mail.Session.getInstance(Session.java:265)
    at EmailSending.launcher.main(launcher.java:34)
    Caused by: java.lang.ClassNotFoundException: com.sun.mail.util.MailLogger
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 4 more
Java Result: 1



How can I watch a full output error message in NetBeans? How to expand "...4 more"?

wind_gan
  • 132
  • 9
  • Welcome to StackOverflow! Could you please add the part of your code which throws the exception? – Benesh Mar 21 '14 at 16:29
  • Take a look at http://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java – Benesh Mar 21 '14 at 16:53
  • Thank you, but my question is about how I can watch the whole error message. – wind_gan Mar 21 '14 at 16:58
  • possible duplicate of [How do I increase the number of displayed lines of a Java stack trace dump?](http://stackoverflow.com/questions/1167888/how-do-i-increase-the-number-of-displayed-lines-of-a-java-stack-trace-dump) – andersschuller Mar 21 '14 at 19:30

1 Answers1

1

In case you haven't figured it out, the cause of that exception is that you haven't added the right JavaMail library to your project. See this JavaMail FAQ entry.

If you're using Maven, you might want to refer to the Maven coordinates for JavaMail listed here. You want com.sun.mail:javax.mail.

Bill Shannon
  • 29,579
  • 6
  • 38
  • 40