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;

    }

번호 제목 글쓴이 날짜 조회 수
326 (Bard) the request was rejected because no multipart boundary was found file 황제낙엽 2023.08.23 727
325 (Bard) multipart/form-data 요청 처리를 위한 MultipartHttpServletRequest file 황제낙엽 2023.08.21 583
324 JPA 개요 황제낙엽 2023.07.25 708
323 javax.mail 샘플 몇가지 (테스트 수행전) 황제낙엽 2023.06.26 915
» java 프로그램으로 회원가입용 인증 메일을 보내는 방법 (from naver / 테스트 성공) file 황제낙엽 2023.06.24 924
321 java 프로그램으로 회원가입용 인증 메일을 보내는 방법 (from bing / 테스트 실패) [1] 황제낙엽 2023.06.23 1040
320 base64 encode, decode 황제낙엽 2023.06.12 660
319 BASE64Encoder, BASE64Decoder 의 deprecated 황제낙엽 2023.06.12 935
318 문자의 ASCII 값 테이블 - String.charAt() file 황제낙엽 2023.03.28 800
317 java로 알파벳 대소문자를 랜덤으로 조합하는 코드 만들어줘 (ChatGPT) 황제낙엽 2023.03.28 655
316 ajax 로 post 데이터를 servlet 으로 전달 받기 (with nexacro) [1] secret 황제낙엽 2023.02.26 0
315 구글 클라우드 비전 API 사용하기 (Google Cloud Vision API) 황제낙엽 2023.02.22 688
314 람다식(Lambda Expressions in Java) file 황제낙엽 2022.12.03 1224
313 ConcurrentLinkedQueue와 LinkedBlockingQueue 황제낙엽 2022.04.06 826
312 java.util.Queue file 황제낙엽 2022.04.06 8985
311 숫자형 클래스 BigInterger (int, long 범위 초과) 황제낙엽 2022.01.16 1088
310 LocalDate.now() 오늘 날짜 황제낙엽 2022.01.16 657
309 [java.lang.ProcessBuilder] “매개변수가 틀립니다” 혹은 ”Cannot run program” 황제낙엽 2021.10.15 1028
308 특정 경로에서 쉘 명령어 실행하기 (ProcessBuilder) 황제낙엽 2021.10.08 798
307 HP-UX, IBM-AIX 황제낙엽 2021.06.23 1079