我正在创建一个用于在 java 中发送电子邮件的应用程序,一切都已设置并正常工作。但错误是当我尝试登录 Hotmail 帐户时,它显示我在 catch 块中提供的不正确的电子邮件和密码错误。但是我第一次登录yahoo或者gmail的时候登录hotmail,之后我可以登录hotmail,但是我不能先登录hotmail,为什么?!代码如下
private void cmd_loginActionPerformed(java.awt.event.ActionEvent evt) {
user = txt_user.getText();
pass = txt_pass.getText();
int combo = combo_ac.getSelectedIndex();
if(combo==0){
try{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session sessin = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(user+"@gmail.com", pass);
}
}
);
new Gmail().setVisible(true);
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Incorrect Email or Password!");
}
}else if(combo==1){
try{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.live.com");
props.put("mail.smtp.socketFactory.port", "25");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "25");
Session sessin = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(user+"@hotmail.com", pass);
}
}
);
new Hotmail().setVisible(true);
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Incorrect Email or Password!");
}
}else if(combo==2){
try{
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.mail.yahoo.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session sessin = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(user+"@yahoo.com", pass);
}
}
);
new Yahoo().setVisible(true);
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Incorrect Email or Password!");
}
}
}