首页 > 解决方案 > 程序确实在 Eclipse 中发送邮件,但在 jarred 时不发送

问题描述

我的程序应该自动发送邮件。这在 Eclipse 中确实可以正常工作,但是当我将它打包(显然将所需的库打包到 jar 中以使其成为可运行的 jar)时,它以某种方式不发送邮件。所以当然,我的第一个想法是我提取的库会有问题,但我已经仔细检查了每个选项。

还有其他原因导致这种情况发生吗?

    // sets SMTP server properties
    Properties properties = new Properties();
    properties.put("mail.smtp.host", host);
    properties.put("mail.smtp.port", port);
    properties.put("mail.smtp.auth", "false");
    properties.put("mail.smtp.starttls.enable", "false");
    properties.put("mail.user", userName);
    properties.put("mail.password", password);

    // creates a new session with an authenticator
    Authenticator auth = new Authenticator() {
        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(userName, password);
        }
    };
    Session session = Session.getInstance(properties, auth);

    // creates a new e-mail message
    Message msg = new MimeMessage(session);

这是出错的地方"Message msg = new MimeMessage(session)"

标签: java

解决方案


推荐阅读