java - 清理和构建后无法使用 jar 文件发送 Java-Mail - NetBeans - JDK8
问题描述
从 NetBeans IDE 运行 GUI 应用程序时一切顺利,邮件发送没有任何问题,但是当清理并构建 jar 文件时,我无法发送任何邮件注意:没有任何例外
代码:
public void sendVerificationMail( String To, String name, String group, String pass) {
Thread t = new Thread() {
@Override
public void run() {
try {
String to = To;
String from = user_name;
String host = "smtp.gmail.com";
Properties properties = new Properties();
properties.put("mail.smtp.host", host);
properties.put("mail.smtp.port", "465");
properties.put("mail.smtp.ssl.enable", "true");
properties.put("mail.smtp.auth", "true");
//properties.put("java.net.preferIPv4Stack", "true");
Session session = Session.getDefaultInstance(properties,
new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user_name, user_pass);
}
}
);
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Verification-Code");
message.setText("Hello, " + name + "\n" + "Your Code is : " + pass + " ,"
+ "Please Use It For Login Purpose" + "\n" + "Best Regards!" + "\n" + "Eng: Hamdy Elasawy\n"
+ "RPA Developers Group #: " + group);
Transport.send(message);
} catch (Exception e) {
// JOptionPane.showMessageDialog(null, e);
}
}
};
t.start();
}
使用:-NetBeans IDE -JDK 8
谢谢
解决方案
推荐阅读
- visual-studio-code - neovim vscode 替换光标下的单词
- javascript - HTML 内容在 window.location.href 中不起作用
- javascript - Blender坐标到three.js
- c++ - 完全迷失在 C++ 中(第一周学习)
- react-native - React Native Redux Actions 功能问题
- prolog - Atom 出现在 Section T1 将所有 a 重写为 c
- excel - 根据我要减去的分钟数检查给定时间的上一个时间间隔
- c++ - Cmake:设置 rpath
- grails - 为 NullObject 添加扩展方法
- c++ - 将二维数组作为参数传递