2013-08-19 3 views
0

전자 메일을 보내는 Java 응용 프로그램이 있습니다. 하지만 코드를 실행할 때 다음 예외가 발생합니다. 또한 인증 설정을 확인하고 포트 번호는 485이지만 여전히 오류가 남아 있습니다. 여기 javax.mail.MessagingException : SMTP 호스트에 연결할 수 없습니다. smtp.gmail.com, 포트 : 587

DEBUG: setDebug: JavaMail version 1.4.4 
DEBUG: getProvider() returning  
javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, 
Inc] 
DEBUG SMTP: useEhlo true, useAuth true 
DEBUG SMTP: useEhlo true, useAuth true 
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false 
javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 
587; 
nested exception is: 
java.net.ConnectException: Connection refused: 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:317) 
at javax.mail.Service.connect(Service.java:176) 
at javax.mail.Service.connect(Service.java:125) 
at javax.mail.Transport.send0(Transport.java:194) 
at javax.mail.Transport.send(Transport.java:124) 
at SimpleMailWithAttachment.<init>(SimpleMailWithAttachment.java:46) 
at SimpleMailWithAttachment.main(SimpleMailWithAttachment.java:64) 
    Caused by: java.net.ConnectException: Connection refused: connect 

내가 메일을 당신이 인증없이 Gmail을 사용할 수 있다고 생각하지 않습니다

public SimpleMailWithAttachment() { 
    Properties props = System.getProperties(); 
    props.setProperty("mail.smtp.port", "587"); 
    props.setProperty("mail.smtp.host", "smtp.gmail.com"); 
    props.setProperty("mail.smtp.starttls.enable", "true"); 
    props.setProperty("mail.smtp.auth", "true"); 

    Authenticator auth = new MyAuthenticator(); 
    Session smtpSession = Session.getInstance(props, auth); 
    smtpSession.setDebug(true); 

    MimeMessage message = new MimeMessage(smtpSession); 
    try { 
     message.setFrom(new InternetAddress(email)); 

     message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); 
     final String encoding = "UTF-8"; 

     message.setSubject(subject, encoding); 
     message.setText(text, encoding); 
     Transport.send(message); 
    } catch (Exception ex) { 
     ex.printStackTrace(); 
    } 
} 

static class MyAuthenticator extends Authenticator { 

    public PasswordAuthentication getPasswordAuthentication() { 
     String username = "******@gmail.com"; 
     String password = "*****"; 
     return new PasswordAuthentication(username, password); 

    } 
} 

답변

1

를 보내려고하는 데 사용하고있는 코드입니다. 당신은 할 587

이미 포트 (465)와 코드를 시도 http://email.about.com/od/accessinggmail/f/Gmail_SMTP_Settings.htm

+0

참조 포트 (465)를 사용할 필요가 있지만, 여전히 같은 예외와 함께 실패합니다. 이 문제를 어떻게 해결할 수 있을지에 대한 제안이 있으십니까? – user407269

관련 문제