Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 기본적으로 Transport.send로 메일발송요청을 실행할 수 있으나,
- // 해당 메일이 정상적으로 요청되었는지 확인하기 위해 EventListenner 등록이 필요하여
- // 세션으로 부터 Transport 객체를 참조하여 실행한다.
- tr = session.getTransport("smtp");
- // 연결
- tr.connect();
- // EventListener 등록
- tr.addTransportListener(new TransportListener() {
- public void messageDelivered(TransportEvent ev) {
- /*
- Address[] vaildAddr = ev.getValidSentAddresses();
- String strMail = "";
- if(vaildAddr != null) {
- for(int index = 0 ; index < vaildAddr.length ; index++) {
- strMail += ("".equals(strMail) ? "" : ", ") + vaildAddr[index].toString();
- }
- }
- log.info("sendMail() delivered - vaild address : " + strMail);
- */
- }
- public void messageNotDelivered(TransportEvent ev) {
- Address[] invaildAddr = ev.getInvalidAddresses();
- Address[] unsentAddr = ev.getValidUnsentAddresses();
- String strInvaildMail = "";
- String strUnsentMail = "";
- if(invaildAddr != null) {
- for(int index = 0 ; index < invaildAddr.length ; index++) {
- strInvaildMail += ("".equals(strInvaildMail) ? "" : ", ") + invaildAddr[index].toString();
- }
- for(int index = 0 ; index < unsentAddr.length ; index++) {
- strUnsentMail += ("".equals(strUnsentMail) ? "" : ", ") + unsentAddr[index].toString();
- }
- }
- log.info("sendMail() not delivered - invaild address : " + strInvaildMail + " / unsent address : " + strUnsentMail);
- }
- public void messagePartiallyDelivered(TransportEvent ev) {
- Address[] invaildAddr = ev.getInvalidAddresses();
- Address[] unsentAddr = ev.getValidUnsentAddresses();
- String strInvaildMail = "";
- String strUnsentMail = "";
- if(invaildAddr != null) {
- for(int index = 0 ; index < invaildAddr.length ; index++) {
- strInvaildMail += ("".equals(strInvaildMail) ? "" : ", ") + invaildAddr[index].toString();
- }
- for(int index = 0 ; index < unsentAddr.length ; index++) {
- strUnsentMail += ("".equals(strUnsentMail) ? "" : ", ") + unsentAddr[index].toString();
- }
- }
- log.info("sendMail() partially delivered - invaild address : " + strInvaildMail + " / unsent address : " + strUnsentMail);
- }
- });
- // 기존에 사용하던 send() 메소드의 경우 리스너에게 이벤트를 전달하지 않으므로
- // 송신상태를 리스너로 전달하는 sendMessage() 메소드로 변경
- //tr.send(mimeMsg);
- tr.sendMessage(mimeMsg, mimeMsg.getAllRecipients()); // 메일 발송요청
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement