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;

    }

번호 제목 글쓴이 날짜 조회 수
162 linux(ubuntu) 의 jdk 21 이 설정된 환경에서 jdk 17 로 다운그레이드 절차 황제낙엽 2025.09.22 61
161 google-auth-library-oauth2-http 라이브러리 다운로드 황제낙엽 2023.11.19 2325
160 firebase-admin-java 라이브러리 다운로드 (firebase admin sdk library) 황제낙엽 2023.11.19 1179
159 Enum 활용 (개인블로그, Effective Java) file 황제낙엽 2023.11.02 1034
158 Enum 활용 (우아한기술블로그) file 황제낙엽 2023.11.02 1003
157 JPA 개요 황제낙엽 2023.07.25 739
156 javax.mail 샘플 몇가지 (테스트 수행전) 황제낙엽 2023.06.26 944
» java 프로그램으로 회원가입용 인증 메일을 보내는 방법 (from naver / 테스트 성공) file 황제낙엽 2023.06.24 962
154 java 프로그램으로 회원가입용 인증 메일을 보내는 방법 (from bing / 테스트 실패) [1] 황제낙엽 2023.06.23 1065
153 base64 encode, decode 황제낙엽 2023.06.12 699
152 BASE64Encoder, BASE64Decoder 의 deprecated 황제낙엽 2023.06.12 974
151 java로 알파벳 대소문자를 랜덤으로 조합하는 코드 만들어줘 (ChatGPT) 황제낙엽 2023.03.28 697
150 구글 클라우드 비전 API 사용하기 (Google Cloud Vision API) 황제낙엽 2023.02.22 721
149 람다식(Lambda Expressions in Java) file 황제낙엽 2022.12.03 1263
148 ConcurrentLinkedQueue와 LinkedBlockingQueue 황제낙엽 2022.04.06 853
147 java.util.Queue file 황제낙엽 2022.04.06 9191
146 HP-UX, IBM-AIX 황제낙엽 2021.06.23 1118
145 람다(Lambda)와 함수형 인터페이스 황제낙엽 2021.05.10 1018
144 for, while 등의 loop구문에서 sleep하기 황제낙엽 2020.12.04 839
143 미디어 파일의 metadata를 읽자 (metadata-extractor) file 황제낙엽 2020.08.30 1549