首页 > 解决方案 > 清理和构建后无法使用 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

谢谢

标签: javaemailuser-interface

解决方案


推荐阅读