3

下面是我正在使用的代码:

        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);
        }

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

4

1 回答 1

2

Yes, you need to set it before the Transport object is created. Move it up one line.

Note also that starting with JavaMail 1.4.5 the details of the authentication exchange are not displayed by default. You'll need to set "mail.debug.auth" to "true" to see that.

于 2012-11-07T20:41:49.940 回答