java - 程序确实在 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)"
解决方案
推荐阅读
- c# - 在 Linux 上从 .NET Core 使用 NTLM 身份验证调用 WCF 服务
- java - 如何在超类中使用子类进行多态性?
- javascript - 需要下拉菜单来保持焦点(保持打开状态),因为数据表中的结果正在更新(这会导致焦点消失)
- git - 删除 github 中的第一个提交
- xamarin - 我们如何将数据绑定到 Xamarin Forms 中的“页脚”
- java - 编码为 UTF-8。编码字符,例如。ö 到 ö¶
- java - 如何在发送 post 方法时修复“尝试从空的一对一属性分配 id”?
- node.js - Create React App 入门 - “找不到模块”
- python - 如何为 Python PrettyTable 创建页脚
- php - 使用php7从mysql打印数据