简体   繁体   中英

Why am I getting this error with JavaMail in IntelliJ?

I've been trying to send an email using the JavaMail API and Gmail SMTP. I am using IntelliJ IDEA Community Edition 2020.3.3. After following this tutorial and using this code (the one about Gmail SMTP with TLS), I keep getting the same error:

1st link - error

Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataHandler
    at mainPackage.JavaMailUtil.prepareMessage(JavaMailUtil.java:40)
    at mainPackage.JavaMailUtil.sendMail(JavaMailUtil.java:28)
    at mainPackage.JavaMail.main(JavaMail.java:5)
Caused by: java.lang.ClassNotFoundException: javax.activation.DataHandler
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 3 more

2nd link - error

Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataHandler
    at lukemaster06.emailPackage.SendEmailTLS.main(SendEmailTLS.java:30)
Caused by: java.lang.ClassNotFoundException: javax.activation.DataHandler
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
    ... 1 more

Since I'm fairly new to Java programming, I don't understand what I'm doing wrong. Thank you in advance for the help.

To see the IntelliJ IDEA projects, visit this GitHub page . If anything does wrong with them, let me know. You can also email me for more discussion-based conversations: public.lukemaster06@gmail.com

Which version of Java are you using? It's possible that since the DataHandler comes from JavaBeans Activation Framework you may not have it, since the last version of Java that included it was Java 1.8.

If that's the case you need to include this library in your project: https://mvnrepository.com/artifact/com.sun.activation/javax.activation/1.2.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM