博主在看廖雪峰老师的sendEmail章节时,发现javax包导入有问题
问题一
javax.activation.DataHandler and javax.mail.internet.MimeMultipart
然后查了一下大概意思javax是易主了,且jdk9后对api不继续默认接入了,需要加入activation.jar,
JDK 9 disables access to many of the javax.* APIs by default, javax activation is now deprecated.
于是我又更换成jakarta包,然后又报错了
问题二
jakarta.activation.spi.MailcapRegistryProvider cannot be found
于是博主添加了avtivation.jar包 后发现又报错了查了一下 需要添加 angus-activation-1.1.0.jar和angus-mail-1.1.0.jar
加了这两个依赖就可以成功运行了。 此外有一点要注意的是,password是邮箱的激活码不是密码,具体怎么得到可以百度。
把maven依赖贴在下面,大家可以直接复制。
<!-- https://mvnrepository.com/artifact/jakarta.servlet/jakarta.servlet-api -->
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/jakarta.activation/jakarta.activation-api -->
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sun.mail/jakarta.mail -->
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>2.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.angus/angus-mail -->
<dependency>
<groupId>org.eclipse.angus</groupId>
<artifactId>angus-mail</artifactId>
<version>2.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.angus/angus-activation -->
<dependency>
<groupId>org.eclipse.angus</groupId>
<artifactId>angus-activation</artifactId>
<version>2.0.1</version>
</dependency>