2017-11-21 9 views
1

성공적으로 작동하는 gmail을 가진 샘플 프로그램을 시도했으며 주로 서버와 포트 이름을 변경하여 Outlook을 수정하려고했습니다. 다음과 같은 오류가 발생했습니다 :SMTP 호스트의 연결 오류 : smtp.outlook.com, 포트 : 25

javax.mail.MessagingException : SMTP 호스트에 연결할 수 없습니다 : smtp.outlook.com, 포트 : 25; 중첩 예외는 다음과 같습니다. javax.net.ssl.SSLException : 인식 할 수없는 SSL 메시지, 일반 텍스트 연결?

package mailsend; 

import javax.mail.Authenticator; 
import java.util.Properties; 

import javax.mail.Message; 
import javax.mail.PasswordAuthentication; 
import javax.mail.Session; 
import javax.mail.Transport; 
import javax.mail.internet.InternetAddress; 
import javax.mail.internet.MimeMessage; 



public class Outlook { 
    final String senderEmailID = "xxx"; 
    final String senderPassword = "xxx"; 
    final String emailSMTPserver = "smtp.outlook.com"; 
    //final String emailSMTPserver = "Smtp.live.com"; 
    final String emailServerPort = "25"; 
    String receiverEmailID = null; 
    static String emailSubject = "Test Mail"; 
    static String emailBody = ":)"; 

    //mail.smtp.ssl.enable = "true"; 
    public Outlook(String receiverEmailID, String Subject, String Body) { 
     this.receiverEmailID = receiverEmailID; 
     this.emailSubject = Subject; 
     this.emailBody = Body; 
     Properties props = new Properties(); 
     //System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol"); 
     props.put("mail.smtp.user", senderEmailID); 
     props.put("mail.smtp.host", emailSMTPserver); 
     props.put("mail.smtp.port", emailServerPort); 
     props.put("mail.smtp.starttls.enable", "true"); 
     props.put("mail.smtp.auth", "true"); 
     props.put("mail.smtp.socketFactory.port", emailServerPort); 
     props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); 
     props.put("mail.smtp.socketFactory.fallback", "false"); 
     props.put("mail.smtp.ssl.enable", "true"); 
     /*prop key="mail.smtp.starttls.enable" */ 
     SecurityManager security = System.getSecurityManager(); 
     //mail.smtp.ssl.enable "true" 

     try { 
      // SMTPAuthenticator auth = new SMTPAuthenticator(); 
      Session session = Session.getInstance(props, new SMTPAuthenticator("xxx", xxx")); 
      MimeMessage msg = new MimeMessage(session); 
      msg.setText(emailBody); 
      msg.setSubject(emailSubject); 
      msg.setFrom(new InternetAddress(senderEmailID)); 
      msg.addRecipient(Message.RecipientType.TO, new InternetAddress(receiverEmailID)); 
      Transport.send(msg); 
      //sendMessage(msg, msg.getAllRecipients()); 
      System.out.println("Message send Successfully:)"); 
     } 

     catch (Exception mex) { 
      mex.printStackTrace(); 
     } 
    } 

    public class SMTPAuthenticator extends Authenticator { 
     String user; 
     String pwd; 

     SMTPAuthenticator(String senderEmailID, String senderPassword) { 

      super(); 
      this.user = senderEmailID; 
      this.pwd = senderPassword; 

     } 

     public PasswordAuthentication getPasswordAuthentication() { 
      return new PasswordAuthentication(user, pwd); 
     } 
    } 

    public static void main(String[] args) { 

     Outlook obj1 = new Outlook("xxx", "hi", "test"); 

    } 
} 
+0

https://stackoverflow.com/questions/6532273/unrecognized-ssl-message-plaintext-connection-exception –

답변

0

당신은 smtp-mail.outlook.com에 포트 587에 TLS를 사용하여 연결해야합니다

여기로 아래에있는 내 코드입니다.