2016-06-13 5 views
0

javamail api를 통해 smtp 서버를 사용하여 이메일을 보내려고했습니다. 내가 인증을 사용하지 않도록 노력했다smtp server-javamail을 사용하여 메일을 보낼 수 없습니다.

private Session getSession() { 
    Authenticator authenticator = new Authenticator(); 

    Properties properties = System.getProperties(); 
    properties.setProperty("mail.smtp.submitter", authenticator.getPasswordAuthentication().getUserName()); 
    properties.setProperty("mail.smtp.auth", "false"); 
    properties.setProperty("mail.smtp.starttls.enable", "false"); 
    properties.setProperty("mail.smtp.host", "smtp.hostname.com");  
    properties.setProperty("mail.smtp.port", "587"); 
    properties.setProperty("mail.smtp.ssl.trust", "smtp.hostname.com"); 
    properties.setProperty("java.net.preferIPv4Stack" , "true"); 

    return Session.getInstance(properties, authenticator); 
} 

private class Authenticator extends javax.mail.Authenticator { 
    private PasswordAuthentication authentication; 

    public Authenticator() { 
     String username = "username"; 
     String password = "password"; 
     authentication = new PasswordAuthentication(username, password); 
    } 

    protected PasswordAuthentication getPasswordAuthentication() { 
     return authentication; 
    } 
} 

일부 게시물에 의해 제안도에 대한 해상도에 넣어 :

여기
javax.mail.MessagingException: Could not connect to SMTP host: smtp.host.com, port: 587; 
nested exception is:java.net.SocketException: Permission denied: connect 

내가 메일에 대한 PropertiesSession 개체를 만드는 방법은 다음과 같습니다 나는 다음과 같은 오류가 발생합니다 이 게시물에 따른 IPv4 환경 설정 : JavaMail API to iMail -- java.net.SocketException: Permission denied: connect

하지만 여전히 동일한 오류가 발생합니다. 이 문제가 해결 될 수있는 다른 방법이 있습니까?

감사합니다.

+0

예를 들어 Thunderbird와 같은 일반 메일 클라이언트에서 동일한 구성 값을 사용하여 유효한지 확인 했습니까? – mjn

+0

[JavaMail API에서 iMail 로의 가능한 복제 - java.net.SocketException : 권한이 거부되었습니다 : 연결] (http://stackoverflow.com/questions/12901475/javamail-api-to-imail-java-net-socketexception-permission -denied-connect) – mjn

답변

0

비슷한 문제가 발생했습니다. here.

문제가 안티 바이러스 또는 요청을 차단하는 방화벽과 관련되어 있는지 확인하십시오.

0

방화벽에서 스위치를 끄고 jar/lib/security에 누락 된 보안 인증서 을 찾았습니다.이 문제에 이미 직면했습니다. phpmailer lib를 PHP에서 사용하고 API에서 코드를 사용할 수 있도록해야합니다. 당신은 PHP를 시도 할 수 있습니다.