Advertisement
Guest User

Untitled

a guest
Apr 10th, 2020
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.04 KB | None | 0 0
  1.  
  2.             // 기본적으로 Transport.send로 메일발송요청을 실행할 수 있으나,
  3.             // 해당 메일이 정상적으로 요청되었는지 확인하기 위해 EventListenner 등록이 필요하여
  4.             // 세션으로 부터 Transport 객체를 참조하여 실행한다.
  5.             tr = session.getTransport("smtp");
  6.  
  7.             // 연결
  8.             tr.connect();
  9.            
  10.             // EventListener 등록
  11.             tr.addTransportListener(new TransportListener() {
  12.  
  13.                 public void messageDelivered(TransportEvent ev) {
  14.                     /*
  15.                     Address[] vaildAddr = ev.getValidSentAddresses();
  16.                    
  17.                     String strMail = "";
  18.                    
  19.                     if(vaildAddr != null)   {
  20.                         for(int index = 0 ; index < vaildAddr.length ; index++) {
  21.                             strMail += ("".equals(strMail) ? "" : ", ") + vaildAddr[index].toString();
  22.                         }
  23.                     }
  24.                    
  25.                     log.info("sendMail() delivered - vaild address : " + strMail);
  26.                     */
  27.                 }
  28.  
  29.                 public void messageNotDelivered(TransportEvent ev) {
  30.                     Address[] invaildAddr = ev.getInvalidAddresses();
  31.                     Address[] unsentAddr = ev.getValidUnsentAddresses();
  32.                     String strInvaildMail = "";
  33.                     String strUnsentMail = "";
  34.                    
  35.                     if(invaildAddr != null) {
  36.                         for(int index = 0 ; index < invaildAddr.length ; index++)   {
  37.                             strInvaildMail += ("".equals(strInvaildMail) ? "" : ", ") + invaildAddr[index].toString();
  38.                         }
  39.                         for(int index = 0 ; index < unsentAddr.length ; index++)    {
  40.                             strUnsentMail += ("".equals(strUnsentMail) ? "" : ", ") + unsentAddr[index].toString();
  41.                         }
  42.                     }
  43.                    
  44.                     log.info("sendMail() not delivered - invaild address : " + strInvaildMail + " / unsent address : " + strUnsentMail);
  45.                 }
  46.  
  47.                 public void messagePartiallyDelivered(TransportEvent ev) {
  48.                     Address[] invaildAddr = ev.getInvalidAddresses();
  49.                     Address[] unsentAddr = ev.getValidUnsentAddresses();
  50.                     String strInvaildMail = "";
  51.                     String strUnsentMail = "";
  52.                    
  53.                     if(invaildAddr != null) {
  54.                         for(int index = 0 ; index < invaildAddr.length ; index++)   {
  55.                             strInvaildMail += ("".equals(strInvaildMail) ? "" : ", ") + invaildAddr[index].toString();
  56.                         }
  57.                         for(int index = 0 ; index < unsentAddr.length ; index++)    {
  58.                             strUnsentMail += ("".equals(strUnsentMail) ? "" : ", ") + unsentAddr[index].toString();
  59.                         }
  60.                     }
  61.                    
  62.                     log.info("sendMail() partially delivered - invaild address : " + strInvaildMail + " / unsent address : " + strUnsentMail);
  63.                 }
  64.             });
  65.  
  66.             // 기존에 사용하던 send() 메소드의 경우 리스너에게 이벤트를 전달하지 않으므로
  67.             // 송신상태를 리스너로 전달하는 sendMessage() 메소드로 변경
  68.             //tr.send(mimeMsg);
  69.             tr.sendMessage(mimeMsg, mimeMsg.getAllRecipients());            // 메일 발송요청
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement