authentication - 如何使用 JavaMail 调试 SMTP 身份验证错误?

下面是我使用的代码:

        Properties props = System.getProperties();
        props.put("mail.smtp.auth", "true");
        // props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", server);
        props.put("mail.smtp.port", "25");
        Session session = Session.getInstance(props);
        Transport transport = null;
        try {
            transport = session.getTransport("smtp");
            session.setDebug(true);
            transport.connect(server, username, password);
        } catch(AuthenticationFailedException message){
            System.out.println("Authentication Failed... terminating!");
            System.out.println(message);
            System.exit(16);
        }

不幸的是,我没有看到 session 握手。我是否将 setDebug 放在了错误的位置?

最佳答案

是的,您需要在创建传输对象之前设置它。将其上移一行。

另请注意,从 JavaMail 1.4.5 开始,默认情况下不会显示身份验证交换的详细信息。您需要将“mail.debug.auth”设置为“true”才能看到。

https://stackoverflow.com/questions/13277222/

相关文章:

google-chrome - "Extension Install Failure: Packag

c# - 将 DependencyProperty 转发到用户控件中包含的控件

php - 在 foreach 循环中使用数组变量

sql - 当一个值为 null 时未拾取不匹配

.net - 如果我有一个返回不同列表的方法,我应该让它返回 ISet 而不是 IEnumer

python - 从 `scipy.ndimage.map_coordinates` 输出向量/数组

python - 将 Python 正则表达式用于 Twitter 数据

ruby-on-rails - 在 rails 3 中连接两个表

php - Wordpress 主题选项不会保存

.net - 即使所有新发布者都有签名证书,未知发布者警告是否真的会出现?