java.lang.ClassNotFoundException: com.sun.mail.util.MessageRemovedIOException

Problem

Use JavaMail API to send Email via GMail smtp server, but hit the following error message :


Caused by: java.lang.ClassNotFoundException: com.sun.mail.util.MessageRemovedIOException
	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:307)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
	... 1 more

P.S The javaee.jar library is included.

Solution

To solve it, you need to include the mail.jar as well, which you can get it from your JavaEE SDK folder or JavaMail API official page.

Again, to send Email via JavaMail API, you need to include both javaee.jar and mail.jar libraries.

About the Author

author image
mkyong
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

avatar
4 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
4 Comment authors
Shane RowattBeomjun ParkOttoAdd Recent comment authors
newest oldest most voted
Add
Guest
Add

Hi, I am trying to write a program that sends email using javaMail. I am using maven to get the jars but I am getting the following exception.Can anybody help me get the right jars via maven ? The one I have are the following in the maven POM file: javax.mail javax.mail-api 1.4.5 javax.activation activation 1.1.1 Thanks

Otto
Guest
Otto

Sir,
I did include both of the jars,
but it still gave me the

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: com/sun/mail/util/MessageRemovedIOException

error…

Shane Rowatt
Guest
Shane Rowatt

If you’re using maven try these two dependencies:

javax.mail
javax.mail-api
1.5.3

com.sun.mail
javax.mail
1.5.3

Add
Guest
Add

Sorry I did not mention the exception:
It is: java.lang.NoClassDefFoundError: com/sun/mail/util/MessageRemovedIOException

Beomjun Park
Guest
Beomjun Park

Thank you, this helped me very much!