2016-06-02 3 views
1

나는 함께 아래와 같은 코드를 사용하여 야후/Gmail로 핫메일에서 메일을 보내려고 smtp.live.com 또는 smtp-mail.outlook.com하지만 점점 오류가 계속 :왜 SMTP 서버를 통해 메일을 보낼 수 없습니까?

String to = SendTo.getText(); 
String from = username; 

     java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); 
     Properties properties = System.getProperties(); 
     properties.put("mail.smtp.ssl.enable","true"); 
     properties.put("mail.smtp.host", "smtp.live.com"); // i try smtp-mail.outlook.com also cant 
     properties.put("mail.smtp.port", 465); 
     properties.put("mail.smtp.auth", "true"); 


     Authenticator authenticator = new Authenticator() { 
     protected PasswordAuthentication getPasswordAuthentication() { 
     return new PasswordAuthentication(username,passwd); 
    }}; 

     Session session = Session.getInstance(properties,authenticator); //default session 

     if(attachment.getText().isEmpty()){ 
       try{ 
      MimeMessage message = new MimeMessage(session); //email message 
      message.setFrom(new InternetAddress(from));  //setting header fields 
      message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); 
      message.setSubject(subjectField.getText()); //subject line 

      //mail body 
      message.setText(TextArea.getText()); 
      Transport transport = session.getTransport("smtp"); 
      transport.connect(host, from, to); 
      //host = smtp.live.com [email protected] [email protected] 
      transport.sendMessage(message, message.getAllRecipients()); 
      transport.close(); 
      System.out.println("Sent message successfully...."); 

ERROR :

javax.mail.MessagingException: Could not connect to SMTP host: smtp.live.com, port: 465; 
    nested exception is: 
    java.net.ConnectException: Connection timed out: connect 
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1934) 
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638) 
    at javax.mail.Service.connect(Service.java:295) 
    at javax.mail.Service.connect(Service.java:176) 
+0

줄 바꿈을 유지하고 읽기 쉽도록 예외를 다시 포맷하십시오. – Neapolitan

+0

해결됨 : 핫메일 사용 transport.connect (host, 587, username, passwd); properties.put ("mail.smtp.starttls.enable", "true"); – javafreak

답변

0

어느 호스트 smtp.live.com 나 호스트 smtp-mail.outlook.com 포트에 연결을 허용하도록 나타납니다 465

당신은 아마에서 포트 587를 사용한다

대신.

관련 문제