下面是我使用的代码:
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/