HumanEducationForLecture / Lastroom

Lastroom club project repository.
0 stars 0 forks source link

확인한번부탁드립나디 #15

Open choiseonghyuk opened 7 years ago

choiseonghyuk commented 7 years ago

\\ package workspace;

import java.util.Properties; import javax.mail.Address; import javax.mail.Authenticator; 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 Test3 {

    public static void sendMail(){
        Properties properties = new Properties();
        properties.put("mail.smtp.user", "senderEmail@gmail.com"); //구글 계정
        properties.put("mail.smtp.host", "smtp.gmail.com");
        properties.put("mail.smtp.port", "465");
        properties.put("mail.smtp.starttls.enable", "true");
        properties.put("mail.smtp.auth", "true");
        properties.put("mail.smtp.debug", "true");
        properties.put("mail.smtp.socketFactory.port", "465");
        properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        properties.put("mail.smtp.socketFactory.fallback", "false");

        try {
            Authenticator auth = new senderAccount();
            Session session = Session.getInstance(properties, auth);
            session.setDebug(true); // 메일을 전송할 때 상세한 상황을 콘솔에 출력한다.
            MimeMessage msg = new MimeMessage(session);

            msg.setSubject("안녕하세요");
            Address fromAddr = new InternetAddress("popstars0906@gmail.com"); // 보내는사람 EMAIL
            msg.setFrom(fromAddr);
            Address toAddr = new InternetAddress("dows5478@naver.com");    //받는사람 EMAIL
            msg.addRecipient(Message.RecipientType.TO, toAddr);
            msg.setContent("회원가입을 축하드립니다", "text/plain;charset=KSC5601"); //메일 전송될 내용
            Transport.send(msg);

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

    private static class senderAccount extends javax.mail.Authenticator {

        public PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("popstars0906", "rladlwl10@"); // @gmail.com 제외한 계정 ID, PASS

        }
    }

} \\

여기서 javax.mail.AuthenticationFailedException 이오류 발생으로찾아보니 아이디와 비밀번호 쪽이 문제라고 확인이되서 여러가지 방법을 찾아봤으나 해결이되지않습니다 조언을구합니다

혹여 포트번호가 문제라면 제포트번호로 바꾸는것인가요 포트번호는 임의의값이 아닌가요?

kwongiho commented 7 years ago

Stack trace 전부 복사하거나 캡쳐해서 올려주실 수 있으신가요?

kwongiho commented 7 years ago

컴퓨터 상에서 사용하는 포트는 65534 번까지 존재하는데요, 그 중 1024번까지의 포트는 "잘 알려진 포트번호"라고 부릅니다.

잘 알려진 포트번호는 이미 예약되어있는 포트번호라 특정한 이유가 없다면 사용할 수 없는 포트번호인데요,

그 중 STMP는 25번 포트가 예약되어있습니다.

제 생각에는 mail.stmp.port 이 부분을 25번으로 바꿔주면 해결될 수도 있다고 생각이 되는데요,

적어주신 465번 포트는 Https(Http Secure)의 port번호입니다. -> 확인해보니 stmp포트가 맞다고 하네요

여기 링크 한번 확인해보시면 앞으로 개발하실 때 많은 도움이 될 것 같네요~!!

choiseonghyuk commented 7 years ago

스택트레이서는 javax.mail.AuthenticationFailedException at javax.mail.Service.connect(Service.java:306) at javax.mail.Service.connect(Service.java:156) at javax.mail.Service.connect(Service.java:105) at javax.mail.Transport.send0(Transport.java:168) at javax.mail.Transport.send(Transport.java:98) at workspace.Test3.sendMail(Test3.java:39) at workspace.Test4.main(Test4.java:8)

이문구를 뱉어냅니당

choiseonghyuk commented 7 years ago

25번으로 수정해도 같은문제가 발생하빈다

kwongiho commented 7 years ago

₩₩₩ properties.put("mail.smtp.user", "senderEmail@gmail.com"); //구글 계정

private static class senderAccount extends javax.mail.Authenticator {

    public PasswordAuthentication getPasswordAuthentication() {
        return new PasswordAuthentication("popstars0906", "rladlwl10@"); // @gmail.com 제외한 계정 ID, PASS

    }
}

₩₩₩

위 코드에서, google의 stmp를 발급받은 계정은 senderEmail@gmail.com인 것 같은데 passwordAuthentication은 popstars0906이라는 계정으로 받아져 있네요.

이 두부분중 하나를 변경해보시겠어요?

choiseonghyuk commented 7 years ago

2차인증을통해 계정권한을모두주는 비밀번호로 변경하니 해결되었습니다

kwongiho commented 7 years ago

굿굿!! 오늘중으로 푸쉬 가능하신가요~?