java.lang.ClassNotFoundException-javax.mail.MessagingException

java.lang.ClassNotFoundException-javax.mail.MessagingException

Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException

If you see below exception while trying to send email using eclipse maven project:

Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 22 more

Answer: You need two jars:

  • mail.jar
  • activation.jar

If you added both jar in your project please check your version. For maven project below dependency gives exception:

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4</version>
</dependency>

Then change it to 1.4.3 version as below:

<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4.3</version>
</dependency>

 

If you are using eclipse change mail.jar to latest version. java.lang.ClassNotFoundException-javax.mail.MessagingException should be fixed.

2 thoughts on “java.lang.ClassNotFoundException-javax.mail.MessagingException”
  1. Hi, I follow the steps into my project but still I get the java.lang.NoClassDefFoundError: javax/mail/MessagingException

Leave a Reply

Your email address will not be published. Required fields are marked *