2017-09-11 1 views
0

다음 코드는 javamail API를 사용하여 Java 응용 프로그램에서 전자 메일 (gmail 사용)을 보내는 데 사용됩니다.요청한 대상에 대한 유효한 인증 경로를 찾을 수 없음 (avast가 설치된 Windows에서)

Linux (Kubuntu 16.04)에서는 제대로 작동하지만 Windows에서는 Avast 바이러스 백신 쉴드가 켜져 있습니다. 나는 모든 똑바로 방패를 사용하지 않으면

public void doSendGmail(){ 
    Connection con = Functions.ConnectToDB(); 
    try { 
     Statement stmt = con.createStatement(); 
     String sqlQuery = "select * from settings"; 
     ResultSet rs = stmt.executeQuery(sqlQuery); 

     while(rs.next()){ 
      String email = rs.getString("Email"); 
      //String pass = rs.getString("Password"); 
      byte [] pass = rs.getBytes("Password"); 

      cipher = Cipher.getInstance("DES/CTR/PKCS5Padding"); 
      cipher.init(Cipher.DECRYPT_MODE, keySpec,ivspec); 
      byte [] plain_text = cipher.doFinal(pass); 

      from = email; 
      password = new String(plain_text); 
     } 

     con.close();// close the connection 

    } catch (Exception e) { 
     JOptionPane.showMessageDialog(this, "Error retrieving email address and password\n"+e.toString(), 
       "Error",JOptionPane.ERROR_MESSAGE); 
    } 

    to = txtTo.getText(); 
    cc = txtCC.getText(); 
    bcc = txtBCC.getText(); 
    subject = txtSubject.getText(); 
    message_body = jtaMessage.getText(); 

    Properties props = new Properties(); 
    props.put("mail.smtp.starttls.enable", "true"); 
    props.put("mail.smtp.auth", "true"); 
    props.put("mail.smtp.host", "smtp.gmail.com"); 
    props.put("mail.smtp.port", "587"); 


    /*use authenticator as username and password are supplied 'on demand' i.e queried from database 
    or supplied via a login dialog*/ 
    Session session = Session.getInstance(props,new javax.mail.Authenticator() { 
     protected PasswordAuthentication getPasswordAuthentication(){ 
      return new PasswordAuthentication(from, password); 
     } 
    }); 

    try {    
     Message message = new MimeMessage(session); 
     message.setFrom(new InternetAddress(from)); 
     message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to)); 
     if(!cc.equals("")){ 
      message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc)); 
     } 
     if(!bcc.equals("")){ 
      message.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(bcc)); 
     } 
     message.setSubject(subject); 

     if(filePathList.isEmpty()){// if a file(s) have not been attached... 
      message.setText(message_body); 
      Transport.send(message); 
     } 
     else{// if a file(s) have been attached 
      MimeBodyPart textPart = new MimeBodyPart(); 
      textPart.setText(message_body);// actual message 
      Multipart multipart = new MimeMultipart();// create multipart message 
      multipart.addBodyPart(textPart);//add the text message to the multipart 

      for(int i =0; i<filePathList.size(); i++){// use for loop to attach file(s) 
       MimeBodyPart attachmentPart = new MimeBodyPart(); 
       DataSource source = new FileDataSource((String)filePathList.get(i)); 
       attachmentPart.setDataHandler(new DataHandler(source)); 
       attachmentPart.setFileName((String)fileList.get(i)); 
       multipart.addBodyPart(attachmentPart);// add the attachment to the multipart 
       message.setContent(multipart);// add the multipart to the message 
      } 
      Transport.send(message); 
     } 

     JOptionPane.showMessageDialog(this, "Message Sent!","Sent",JOptionPane.INFORMATION_MESSAGE); 

    } catch (Exception e) { 
     JOptionPane.showMessageDialog(this, "Error sending email message\n"+e.toString(), 
       "Error",JOptionPane.ERROR_MESSAGE); 
    } 
} 

는 다음과 같은 오류 메시지가

enter image description here

를 표시, 그냥 완벽 메일 메시지를 보냅니다.

어떻게 문제를 해결할 수 있습니까?

다른 바이러스 백신도 동일한 효과를 줍니까?

답변

0

Avast가 서버와의 보안 통신에 을 끼어 들기 때문에 바이러스 나 스팸을 보내는 것을 막을 수 있습니다. 하지만 이 "중간에있는 사람"역할을하기 때문에 예외적으로 바꿔 말하면 연결이 안전하지 않다는 뜻입니다.

JavaMail FAQ

당신이 당신의 신뢰 저장소에 추가합니다 InstallCert 프로그램을 사용하여 똑바로 인증서를 신뢰하는 방법을 설명, 또는 어떻게 mail.smtp.ssl.trust 속성을 설정하여 전혀 인증서를 를 확인하지합니다.

+0

mail.smtp.ssl.trust 속성을 true 및 false로 설정했지만 여전히 작동하지 않았습니다. 즉, props.put ("mail.smtp.ssl.trust", "true"); – David

+0

(위에 링크 된) 부동산 설명을 읽었습니까? "true"로 설정하면 "true"라는 호스트를 트러스트합니다. 모든 호스트를 신뢰하려면 "*"로 설정하십시오. –

+0

그래, 나도 그랬어. 그것은 작동하지 않았다. InstallCert 프로그램을 사용해보고 작동하는지 확인해 보겠습니다. – David

0

이것은 내가 한 것입니다. InstallCert 프로그램을이 링크 https://javaee.github.io/javamail/InstallCert.java에서 다운로드했습니다. 그런 다음 텍스트 편집기 (notepad ++)를 사용하여 파일을 열고 443에서 465 (gmail의 SSL 포트)로 포트를 변경하고 변경 사항을 저장했습니다. 그 후 파일을 컴파일하고 gmail 호스트 인 java InstallCert smtp.gmail.com을 제공하는 프로그램을 실행했습니다. 파일 (jssecacerts)이 생성되었습니다. 이 파일을 $ JAVA_HOME/jre/lib/security 폴더에 복사했습니다. 나는 마침내 모든 avast 방패가있는 전자 메일을 보낼 수 있었다!

관련 문제