Java发邮件:Could not connect to SMTP host: smtp.163.com, port: 25;
这是我的发邮件的函数:
public static boolean SendEmailTest(String toEmailStr, String title, String content, String fromEmail) throws AddressException{
boolean flag = false;
Properties props = new Properties();
Session sendMailSession;
Transport transport;
sendMailSession = Session.getInstance(props, null);
props.put("mail.smtp.host", "smtp.163.com");
props.put("mail.smtp.auth", "ture");
try{
transport = sendMailSession.getTransport("smtp");
System.out.println("1");
transport.connect("smtp.163.com", "joehenu", "qiao1988feng"); //到这里的时候就停下来了
System.out.println("2");
Message newMessage = new MimeMessage(sendMailSession);
System.out.println("3");
//設置mail的主題
String mail_subject = title;
newMessage.setSubject(mail_subject);
Address address[] = {new InternetAddress(fromEmail)};//改变发件人地址
newMessage.addFrom(address);
//設置收件人地址
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(toEmailStr));
//設置mail正文
newMessage.setSentDate(new Date());
String mail_text=content;
newMessage.setContent(mail_text, "text/plain;charset=gb2312");
System.out.println("4");
//保存發送信息
newMessage.saveChanges();
System.out.println("5");
transport.send(newMessage, newMessage.getRecipients(Message.RecipientType.TO));
flag = true;
System.out.println("6");
transport.close();
}catch(Exception e){
System.out.println("7");
flag = false;
System.out.println(e);
}
return flag;
}
下面是log信息:
1
7
javax.mail.MessagingException: Could not connect to SMTP host: smtp.163.com, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out: connect
tmp=false
一直查找不到是什么问题?高手帮忙解决一下呗,小弟多谢了