我的程序应该自动发送邮件。这在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)"
出现问题的地方