在 javafx 项目上使用简单的 java 邮件时出错

问题描述 投票:0回答:1

我在一个测试项目上有这段代码,它工作得很好,但我不知道为什么当我把它放在 javafx 项目的包中时,我想真正使用它:

.from("example", "[email protected]")

Uncompilable code - cannot access jakarta.mail.internet.InternetAddress   class file for jakarta.mail.internet.InternetAddress not found

这是我的模块信息课程

module com.mycompany.proyectodam {
    requires javafx.controls;
    requires javafx.fxml;
    requires java.base;
    requires java.sql;
    requires javafx.graphics;
    requires org.simplejavamail;

    opens com.mycompany.proyectodam to javafx.fxml;
    opens com.mycompany.bd to javafx.base;
    exports com.mycompany.proyectodam;
}

这是代码

import org.simplejavamail.api.email.Email;
import org.simplejavamail.api.mailer.Mailer;
import org.simplejavamail.email.EmailBuilder;
import org.simplejavamail.mailer.MailerBuilder;

public class SendEmail {

    public static void main(String[] args) {
        Email email = EmailBuilder.startingBlank()
                                  .from("example", "[email protected]")
                                  .to("example", "[email protected]")
                                  .withSubject("test subject")
                                  .withPlainText("test")
                                  .buildEmail();

        Mailer mailer = MailerBuilder.withSMTPServer("smtp.office365.com", 587, "[email protected]", "dasdasdasdasdasda")
                                     .buildMailer();
        mailer.sendMail(email);
        System.out.println("Correo enviado con éxito!");
    }
}
javafx jakarta-mail
1个回答
0
投票

最新版本 (8.10.1) 的 simplejavamail 代码 不是模块化的(就 Java 平台模块系统而言)。

文档讨论了很多关于模块的内容。然而,这些并不是定义良好的 Java 模块,每个模块都定义了

module-info.java
。相反,许多模块是自动模块

如果您的代码库中有自动模块,我建议重构以使您的项目非模块化。自动模块无法获得模块化的全部好处(例如,具有明确定义的所需模块和 jlinked 运行时的完整模块化封装)。

要开发依赖于模块化 JavaFX 实现的非模块化项目(删除 module-info.java),则可以:

  1. 使用包含 JavaFX 的 JDK/JRE(例如 Azul 或 Liberica“JDK FA”或“完整 JDK”版本)

  1. 遵循openjfx.io 对于非模块化项目的说明。使用命令行开关将所需的 JavaFX 模块放置在模块路径上。
© www.soinside.com 2019 - 2024. All rights reserved.