sitelink1 https://blog.naver.com/till-its-over/222980880983 
sitelink2  
sitelink3  
sitelink4  
sitelink5  
sitelink6  

다음과 같은 네이버 메일 설정이 필요하다

naver_mail.PNG

 

javax.mail jar 라이브러리는 다음의 경로들중에 하나에서 다운받는다

- https://mvnrepository.com/artifact/javax.mail/mail/1.4.7

- https://mvnrepository.com/artifact/com.sun.mail/javax.mail

 

코드는 다음과 같다 (전송 테스트 성공)

import java.util.Date;

import java.util.Properties;

import javax.mail.Authenticator;

import javax.mail.Message;

import javax.mail.MessagingException;

import javax.mail.PasswordAuthentication;

import javax.mail.Session;

import javax.mail.internet.AddressException;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeMessage;

 

public class TestJavaMail {

 

    public static void main(String[] args) {

         

        Properties p = System.getProperties();

        p.put("mail.smtp.starttls.enable", "true");     // gmail은 true 고정

        p.put("mail.smtp.host", "smtp.naver.com");      // smtp 서버 주소

        p.put("mail.smtp.auth","true");                 // gmail은 true 고정

        p.put("mail.smtp.port", "587");                 // 네이버 포트

           

        Authenticator auth = new MyAuthentication();

        //session 생성 및  MimeMessage생성

        Session session = Session.getDefaultInstance(p, auth);

        MimeMessage msg = new MimeMessage(session);

         

        try{

            //편지보낸시간

            msg.setSentDate(new Date());

            InternetAddress from = new InternetAddress() ;

            from = new InternetAddress("sender_test@naver.com"); //발신자 아이디

            // 이메일 발신자

            msg.setFrom(from);

            // 이메일 수신자

            InternetAddress to = new InternetAddress("receiver_test@gmail.com");

            msg.setRecipient(Message.RecipientType.TO, to);

            // 이메일 제목

            msg.setSubject("메일 전송 테스트", "UTF-8");

            // 이메일 내용

            msg.setText("티스토리 테스트", "UTF-8");

            // 이메일 헤더

            msg.setHeader("content-Type", "text/html");

            //메일보내기

            javax.mail.Transport.send(msg, msg.getAllRecipients());

             

        }catch (AddressException addr_e) {

            addr_e.printStackTrace();

        }catch (MessagingException msg_e) {

            msg_e.printStackTrace();

        }catch (Exception msg_e) {

            msg_e.printStackTrace();

        }

    }

}

 

class MyAuthentication extends Authenticator {

      

    PasswordAuthentication pa;

    public MyAuthentication(){

         

        String id = "test@naver.com";  //네이버 이메일 아이디

        String pw = "test";        //네이버 비밀번호

 

        // ID와 비밀번호를 입력한다.

        pa = new PasswordAuthentication(id, pw);

    }

 

    // 시스템에서 사용하는 인증정보

    public PasswordAuthentication getPasswordAuthentication() {

        return pa;

    }

번호 제목 글쓴이 날짜 조회 수
173 google-auth-library-oauth2-http 라이브러리 다운로드 황제낙엽 2023.11.19 10
172 firebase-admin-java 라이브러리 다운로드 (firebase admin sdk library) 황제낙엽 2023.11.19 1
171 Enum 활용 (개인블로그, Effective Java) file 황제낙엽 2023.11.02 1
170 Enum 활용 (우아한기술블로그) file 황제낙엽 2023.11.02 5
169 [JsonNode] depth 가 여러 단계인 json data 내부를 조회하는 java code 예제 (from Bard) file 황제낙엽 2023.08.09 20
168 JPA 개요 황제낙엽 2023.07.25 3
167 javax.mail 샘플 몇가지 (테스트 수행전) 황제낙엽 2023.06.26 3
» java 프로그램으로 회원가입용 인증 메일을 보내는 방법 (from naver / 테스트 성공) file 황제낙엽 2023.06.24 219
165 java 프로그램으로 회원가입용 인증 메일을 보내는 방법 (from bing / 테스트 실패) [1] 황제낙엽 2023.06.23 3
164 base64 encode, decode 황제낙엽 2023.06.12 8
163 BASE64Encoder, BASE64Decoder 의 deprecated 황제낙엽 2023.06.12 1
162 java로 알파벳 대소문자를 랜덤으로 조합하는 코드 만들어줘 (ChatGPT) 황제낙엽 2023.03.28 1
161 구글 클라우드 비전 API 사용하기 (Google Cloud Vision API) 황제낙엽 2023.02.22 8
160 람다식(Lambda Expressions in Java) file 황제낙엽 2022.12.03 2
159 ConcurrentLinkedQueue와 LinkedBlockingQueue 황제낙엽 2022.04.06 17
158 java.util.Queue file 황제낙엽 2022.04.06 5382
157 HP-UX, IBM-AIX 황제낙엽 2021.06.23 55
156 람다(Lambda)와 함수형 인터페이스 황제낙엽 2021.05.10 19
155 for, while 등의 loop구문에서 sleep하기 황제낙엽 2020.12.04 55
154 미디어 파일의 metadata를 읽자 (metadata-extractor) file 황제낙엽 2020.08.30 583