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;

    }

번호 제목 글쓴이 날짜 조회 수
351 java.lang.IllegalArgumentException 황제낙엽 2010.01.18 130514
350 Using RSS in JSP pages (Informa Project) 황제낙엽 2006.01.10 37829
349 JSP 파일에서 getOutputStream() has already been called for this response 에러 황제낙엽 2013.04.24 11479
348 한글 파일명 깨짐으로 살펴본 다국어 처리 문제 (UTF-8) 황제낙엽 2012.03.22 10121
347 세션의 timeout 설정 >> HttpSession.setMaxInactiveInterval() 황제낙엽 2019.07.03 8311
346 [JSON기초04] 자바 JSON 데이터에서 KEY 값 알아오기 (TIP) 황제낙엽 2017.01.18 6641
345 java.util.Queue file 황제낙엽 2022.04.06 5382
344 쓰레드(Thread)를 중간에 종료시키는 방법 황제낙엽 2017.03.15 5127
343 Java 실행 옵션들 황제낙엽 2017.08.23 3367
342 일본어 전각 반각 변환 예제 소스 .첫번째 file 황제낙엽 2007.01.10 3070
341 byte배열에 대한 CRC 를 계산하는 메서드 (java.util.zip.CRC32) 황제낙엽 2010.03.14 2166
340 UTF형태 파일에서 BOM 제거하기 황제낙엽 2008.06.16 1938
339 File.delete() 와 File.deleteOnExit() 황제낙엽 2019.03.24 1887
338 [대용량 파일 업로드] multipart form parser - http file upload, database 저장 java class 연재2 file 황제낙엽 2009.06.19 1831
337 싱글톤 방식의 테스트용 Temporary Data Access Object 황제낙엽 2017.01.12 1603
336 servlet 에서의 json 한글처리 황제낙엽 2013.04.23 1519
335 날짜, 시간 문자열 값으로 Date 오브젝트로 만들기 >> SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.US) 황제낙엽 2017.10.31 1516
334 J2EE object-caching frameworks (ObjectCache) 황제낙엽 2007.11.02 1495
333 [대용량 파일 업로드] multipart form parser - http file upload 기능 java class 연재1 file 황제낙엽 2009.06.19 1436
332 JavaMail - 네이버 메일 수신하기(POP3) 황제낙엽 2018.08.20 1413