简体   繁体   English

为什么 IntelliJ 中的 JavaMail 会出现此错误?

[英]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.我一直在尝试使用 JavaMail API 和 Gmail ZC2239A92BDE29F0A09F91739 发送 email。 I am using IntelliJ IDEA Community Edition 2020.3.3.我正在使用 IntelliJ IDEA 社区版 2020.3.3。 After following this tutorial and using this code (the one about Gmail SMTP with TLS), I keep getting the same error:在遵循本教程并使用此代码(关于 Gmail SMTP 与 TLS 的代码)后,我不断收到相同的错误:

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.由于我对 Java 编程相当陌生,所以我不明白我做错了什么。 Thank you in advance for the help.预先感谢您的帮助。

To see the IntelliJ IDEA projects, visit this GitHub page .要查看 IntelliJ IDEA 项目,请访问此 GitHub 页面 If anything does wrong with them, let me know.如果他们有什么问题,请告诉我。 You can also email me for more discussion-based conversations: public.lukemaster06@gmail.com您也可以 email 我进行更多基于讨论的对话:public.lukemaster06@gmail.com

Which version of Java are you using?您使用的是哪个版本的 Java? 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.可能由于 DataHandler 来自 JavaBeans 激活框架,您可能没有它,因为包含它的 Java 的最后一个版本是 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如果是这种情况,您需要在项目中包含此库: https://mvnrepository.com/artifact/com.sun.activation/javax.activation/1.2.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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