/**
 * @(#)file    UserListBiz.java
 * @(#)author  Joung Kyu Park
 * @(#)version 1.0
 * @(#)date    May 31, 2007
 * @(#)since   JDK 1.4.2
 *
 * Copyright (c) www.hwenc.co.kr, Inc.
 * All rights reserved.
 * This software is the proprietary information of Hanwha E&C, Inc.
 */
package kr.co.udapsoft.ebid.buyer.quot.purchase.biz;



import java.sql.Connection;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import kr.co.hsnc.common.base.WAFLogger;
import kr.co.hsnc.common.base.WAFMessages;
import kr.co.hsnc.common.logger.Logger;
import kr.co.hsnc.common.sql.RowSet;
import kr.co.hsnc.common.sql.RowSetImpl;
import kr.co.hsnc.common.sql.WAFSQLException;
import kr.co.hsnc.common.sql.persistent.Persistent;
import kr.co.hsnc.common.sql.persistent.PersistentImpl;
import kr.co.hsnc.common.sql.search.Search;
import kr.co.hsnc.common.sql.search.SearchImpl;
import kr.co.hsnc.common.sql.util.RowSetUtility;
import kr.co.hsnc.common.util.ValueObject;
import kr.co.udapsoft.common.sender.MessageSend;
import kr.co.udapsoft.common.sender.SmtpAuth;
import kr.co.udapsoft.ebid.buyer.supplier.purchase.biz.SuppJoinRequestListBiz;



import com.udapsoft.waf.system.Biz;
import com.udapsoft.waf.system.HandlerStorage;





public class QuotPurSuppRegSaveBiz extends Biz {

	public QuotPurSuppRegSaveBiz(HandlerStorage storage) {
		super(storage);
	}

	public void doBiz() throws Exception {

		WAFLogger.debug("event==============>" + storage.getEvent());
		
		if(storage.compareEvent(""))
		{

		}
		else if(storage.compareEvent("DELETE_DATA"))
        {
		   deleteData();
        }else if ( storage.compareEvent("NEW_SAVE_DATA") ) {
        	newSaveData();
        }else if ( storage.compareEvent("NEW_UPDATE_DATA") ) {
        	newUpdateData();
        }
	}
	
	private void newSaveData() throws Exception{

	    boolean success = false;
	    
	    try 
        {
            conn.begin();
            
            String yyyymmdd = (new java.text.SimpleDateFormat ("yyyyMMdd")).format (new java.util.Date());
            params.set("user_id", yyyymmdd);
            
            String corp_no = params.get("corp_reg_no");
            String corp_gubun = "";
            
            corp_no = corp_no.substring(3, 5);
            
            if(corp_no.equals("81") || corp_no.equals("82") || corp_no.equals("83") ||corp_no.equals("84") || corp_no.equals("85") || corp_no.equals("86") || corp_no.equals("87") || corp_no.equals("88"))
            {
                corp_gubun = "1";
            }
            else
            {
                corp_gubun = "2";
            }
            params.set("corp_gubun", corp_gubun); 
            
            
            ValueObject corp_id = getCorp_no(conn.getConnection()); 
            
            if(!corp_id.get("cnt").equals("0"))
            {
                String message = "이미 등록된 사업자 번호 입니다.";
                Exception e = new Exception(message);

                
                ValueObject errMsg = new ValueObject();
                errMsg.set("errMsg", message);
                
                storage.addValueObject("VALUEOBJECT", errMsg);
                super.storage.setSuccess(false);
            }
            else
            {
                try 
                {
                    success = save_info(params); 
                    
                } catch (Exception e) {
                    e.printStackTrace();
                }
                
                
                if(success == true)
                {
                    String message = "등록성공";
                    ValueObject errMsg = new ValueObject();
                    errMsg.set("errMsg", message);
                    storage.addValueObject("VALUEOBJECT", errMsg);
                    
                    super.storage.setSuccess(success);
                }
                else
                {
                    String message = "등록실패";
                    Exception e = new Exception(message);
                    
                    ValueObject errMsg = new ValueObject();
                    errMsg.set("errMsg", message);
                    storage.addValueObject("VALUEOBJECT", errMsg);
                    
                    
                    super.storage.setSuccess(false);
                    throw e;
                }
            }
            
        } catch (Exception e) {
            WAFLogger.error(e);
            e.printStackTrace();
            conn.setRollback();
            throw new Exception(e);
            
        } finally {
            conn.end();
        }   
		
	}
	
	private void newUpdateData() throws Exception{
		
		boolean success = false;
		
		try 
		{
			conn.begin();
			
			String yyyymmdd = (new java.text.SimpleDateFormat ("yyyyMMdd")).format (new java.util.Date());
			params.set("user_id", yyyymmdd);
			
			String corp_no = params.get("corp_reg_no");
			String corp_gubun = "";
			
			corp_no = corp_no.substring(3, 5);
			
			if(corp_no.equals("81") || corp_no.equals("82") || corp_no.equals("83") ||corp_no.equals("84") || corp_no.equals("85") || corp_no.equals("86") || corp_no.equals("87") || corp_no.equals("88"))
			{
				corp_gubun = "1";
			}
			else
			{
				corp_gubun = "2";
			}
			params.set("corp_gubun", corp_gubun); 
			
			
			try 
			{
				success = update_info(params); 
				
			} catch (Exception e) {
				e.printStackTrace();
			}
			
			
			if(success == true)
			{
				String message = "수정성공";
				ValueObject errMsg = new ValueObject();
				errMsg.set("errMsg", message);
				storage.addValueObject("VALUEOBJECT", errMsg);
				
				super.storage.setSuccess(success);
			}
			else
			{
				String message = "수정실패";
				//                WAFLogger.error(message);
				Exception e = new Exception(message);
				
				ValueObject errMsg = new ValueObject();
				errMsg.set("errMsg", message);
				storage.addValueObject("VALUEOBJECT", errMsg);
				
				
				super.storage.setSuccess(false);
				throw e;
			}
			
		} catch (Exception e) {
			WAFLogger.error(e);
			e.printStackTrace();
			conn.setRollback();
			throw new Exception(e);
			
		} finally {
			conn.end();
		}   
		
	}
	
	private void deleteData() throws Exception{
		boolean success = false;
		    
	    super.conn.begin();
	    
	    
	    try {
			success = delete_supp(params);
			
			WAFLogger.debug(success);			
			super.storage.setSuccess(true);

		} catch (Exception e1) {
			ValueObject errMsg = new ValueObject();
			errMsg.set("errMsg", e1.getMessage());
			storage.addValueObject("VALUEOBJECT", errMsg);
			
			storage.setSuccess(false);
			conn.setRollback();
			throw new Exception(e1);
		}finally{
			conn.end();
		}
		    
         
	}
	
	
	/**
	 * 협력업체 마스터 저장
	 * @param params
	 * @return
	 * @throws Exception
	 */
	private boolean save_info(ValueObject params) throws Exception
    {
        
        Persistent persistent = null;
        StringBuffer sqlstr = new StringBuffer();
        
        
        try{
            persistent = new PersistentImpl(super.conn.getConnection());
            
            sqlstr.append("     INSERT INTO QUOT_REG_SUPP_INFO                 \n")
                   .append("     (                                             \n")
                   .append("          QUOT_REG_CORP_ID                          \n")
                   .append("         ,JOB_DIV --P:구매. O:외주                                    \n")
                   .append("         ,IN_OUT_DIV --I:국내, O:국외                              \n")
                   .append("         ,CORP_REG_NO                              \n")
                   .append("         ,CORP_KOR                                 \n")
                   .append("         ,REP_NAME                                 \n")
                   .append("         ,CORP_TEL                                 \n")
                   .append("         ,CHARGE_NAME                              \n")
                   .append("         ,CHARGE_EMAIL                             \n")
                   .append("         ,HP1                                      \n")
                   .append("         ,HP2                                      \n")
                   .append("         ,HP3                                      \n")
                   .append("         ,STATUS_CD                                \n")
                   .append("         ,REMARK                                \n")
                   .append("         ,CRE_BY                                   \n")
                   .append("         ,CRE_DATE                                 \n")
                   .append("     )VALUES(                                      \n")
                   .append("          '"+params.get("p_corp_id")+"'            \n")
                   .append("         ,'"+params.get("job_div")+"'              \n")
                   .append("         ,'"+params.get("IN_OUT_DIV")+"'           \n")
                   .append("         ,'"+params.get("CORP_REG_NO")+"'          \n")
                   .append("         ,'"+params.get("CORP_KOR")+"'             \n")
                   .append("         ,'"+params.get("REP_NAME")+"'             \n")
                   .append("         ,'"+params.get("CORP_TEL")+"'             \n")
                   .append("         ,'"+params.get("CHARGE_NAME")+"'          \n")
                   .append("         ,'"+params.get("email")+"'                \n")
                   .append("         ,'"+params.get("h_phon_1")+"'             \n")
                   .append("         ,'"+params.get("h_phon_2")+"'             \n")
                   .append("         ,'"+params.get("h_phon_3")+"'             \n")
                   .append("         ,'"+params.get("STATUS_CD")+"'            \n")
                   .append("         ,'"+params.get("REMARK")+"'               \n")
                   .append("         ,'"+storage.getUser().get("acct_id")+"'   \n")
                   .append("         ,SYSDATE                                  \n")
                   .append("     )                                             \n");
            
            
            persistent.setStatement(sqlstr.toString());            
            WAFLogger.debug(persistent.getParameters());
            WAFLogger.debug(sqlstr.toString());
            persistent.execute();
            persistent.clearParameters();
            
            return true;
            
            
        } catch(Exception e) {
        	WAFLogger.error("save_info========>" + e);
            e.printStackTrace();
            return false;            
        }
    }
	
	
	private boolean update_info(ValueObject params) throws Exception
    {
        
        Persistent persistent = null;
        StringBuffer sqlstr = new StringBuffer();
        
        
        try{
            
            conn.begin();
            persistent = new PersistentImpl(super.conn.getConnection());
            
            
            sqlstr.append("     UPDATE QUOT_REG_SUPP_INFO SET              \n")
                   .append("           CORP_REG_NO = '"+params.get("CORP_REG_NO").trim()+"'                \n")
                   .append("         , CORP_KOR = '"+params.get("CORP_KOR").trim()+"'                      \n")
                   .append("         , REP_NAME = '"+params.get("REP_NAME").trim()+"'                      \n")
                   .append("         , CORP_TEL = '"+params.get("CORP_TEL").trim()+"'                      \n")
                   .append("         , IN_OUT_DIV = '"+params.get("IN_OUT_DIV").trim()+"'                  \n")
                   .append("         , CHARGE_NAME = '"+params.get("CHARGE_NAME").trim()+"'                \n")
                   .append("         , CHARGE_EMAIL = '"+params.get("email").trim()+"'                     \n")
                   .append("         , HP1 = '"+params.get("h_phon_1").trim()+"'                           \n")
                   .append("         , HP2 = '"+params.get("h_phon_2").trim()+"'                           \n")
                   .append("         , HP3 = '"+params.get("h_phon_3").trim()+"'                           \n")
                   .append("         , STATUS_CD = '"+params.get("STATUS_CD").trim()+"'                    \n")
                   .append("         , REMARK = '"+params.get("REMARK").trim()+"'                          \n")
                   .append("         , UPD_BY = '"+storage.getUser().get("acct_id").trim()+"'              \n")
                   .append("         , UPD_DATE = TO_CHAR(SYSDATE, 'YYYY-MM-DD')                           \n")
                   .append("     WHERE QUOT_REG_CORP_ID = '"+params.get("p_corp_id").trim()+"'             \n");
            
            persistent.setStatement(sqlstr.toString());
            persistent.execute();
            persistent.clearParameters();
            
            return true;
            
            
        } catch(Exception e) {
        	WAFLogger.error("update_info====>" + e);
            e.printStackTrace();
            conn.setRollback();
            return false;            
        }
        
        finally {
            super.conn.end();
        }
    }

        private boolean delete_supp(ValueObject params) throws Exception
        {
            
            Persistent persistent = null;
            StringBuffer sqlstr = new StringBuffer();
            
            
            try{
                
                persistent = new PersistentImpl(conn.getConnection());
                
                
                sqlstr.append("     DELETE FROM  QUOT_REG_SUPP_INFO 			            \n")
                       .append("     WHERE CORP_ID = '"+params.get("p_corp_id").trim()+"'	\n");
                
                
                persistent.setStatement(sqlstr.toString());
                                
                persistent.execute();
                persistent.clearParameters();
                
                return true;
                
                
            } catch(Exception e) {
            	WAFLogger.error("delete_supp====>" + e);
                storage.setMessage(e.getMessage());
                e.printStackTrace();
                throw new Exception(e);
            }
            
        }
        
	
	
	public ValueObject getCorp_no(Connection con) throws Exception{
        
        Persistent persistent_q = null;
        
        
        ValueObject vo = new ValueObject();
        ValueObject row = null;
        StringBuffer sqlstr =  new StringBuffer();
        
        try{
            persistent_q = new PersistentImpl(con);
            
            sqlstr.append("         SELECT COUNT(*) CNT FROM QUOT_REG_SUPP_INFO WHERE CORP_REG_NO = '"+params.get("corp_reg_no")+"' AND JOB_DIV = '"+params.get("job_div")+"'                              \n");
            
            persistent_q.setStatement(sqlstr.toString()); 
            
            row = RowSetUtility.getValueObject(persistent_q.query().getRow(0));
            vo.set("cnt", row.get("cnt"));
        }
        catch(Exception e) {
            e.printStackTrace();
        }finally{
            if(vo == null) vo = new ValueObject();
        }
        return vo;
    }
	
	
	
	/**
   	 * 이메일 전송 메소드(Javamail 사용)
   	 * @param user
   	 * @param from_email
   	 * @param to_name
   	 * @param to_email
   	 */
       public void sendEmail(String toEmail, String sendUser, String mailSubject, String subSubject, StringBuffer mailContent, String gubun) throws Exception{
   		
       	Date today=new Date();
           SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd");       
           String date = formater.format(today);
           
   		// 메일서버 정보와 실제 서버의 주소를 가져온다.
   		RowSet smtpInfo = getSmtpInfo(); 
   		String smtpIp 	= smtpInfo.getRow(0).get("CHG_CODE01");
   		String smtpUser = smtpInfo.getRow(0).get("CHG_CODE02");
   		String smtpPw 	= smtpInfo.getRow(0).get("CHG_CODE03");
   		String link 	= smtpInfo.getRow(0).get("CHG_CODE04");
   		String linkPortal 	= smtpInfo.getRow(0).get("CHG_CODE05");
   		 	   sendUser = smtpInfo.getRow(0).get("CHG_CODE06");
   		/*
   		RowSet userInfo = getUserInfo(sendUser); 
   		String fromEmail = userInfo.getRow(0).get("E_MAIL");
   		String fromName = userInfo.getRow(0).get("USER_NM");
   		String fromDuty = userInfo.getRow(0).get("A_DUTY");
   		String fromDept = userInfo.getRow(0).get("DEPART_DEPT_NM");
   		String fromTel = userInfo.getRow(0).get("TEL_NO");
   		*/
   		Properties properties = new Properties();									// Properties 객체 설정
   		properties.put("mail.transport.protocol", "smtp");							// SMTP 프로토콜 사용
   		properties.put("mail.smtp.host", smtpIp);									// 메일서버 주소 설정
   		properties.put("mail.smtp.port", "25");										// 메일서버 포트 설정
   		properties.put("mail.smtp.auth", true);										// 인증 사용 여부
   		
   		SmtpAuth auth = new SmtpAuth(smtpUser, smtpPw);								// SMTP 인증을 위해서 반드시 필요하다
   		
   		StringBuffer contentBase = new StringBuffer();
   				
   		
   		if(gubun.equals("P")){
   			//구매
   			contentBase.append("				<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>																																		\n");
   			contentBase.append("				<html xmlns='http://www.w3.org/1999/xhtml'>                                                                                                                                                                                                                     \n");
   			contentBase.append("				<head>                                                                                                                                                                                                                                                          \n");
   			contentBase.append("				<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />                                                                                                                                                                                          \n");
   			contentBase.append("				<title>:::협력업체포탈_mailing:::</title>                                                                                                                                                                                                                       	\n");
   			contentBase.append("				<style type='text/css'>                                                                                                                                                                                                                                         \n");
   			contentBase.append("				<!--                                                                                                                                                                                                                                                            \n");
   			contentBase.append("				.style1 {color: #3366CC;font-weight: bold;font-size: 24px; border-bottom:#3366CC dotted 2px;}                                                                                                                                                                   \n");
   			contentBase.append("				.popup_table{width:800px; font-family:dotum; font-size:12px; color:#666666; text-align:left;}                                                                                                                                                                   \n");
   			contentBase.append("				.text_red{font-size:12px; color:#cc0000; height:25px; text-align:left; vertical-align:top; text-indent:10px;}                                                                                                                                                   \n");
   			contentBase.append("				.popup_logo{ background-image:url("+link+"/img/email/popup_logo.gif) ; background-repeat:no-repeat; width:232px;}                                                                                                                                                              \n");
   			contentBase.append("				.popup_title{font-family:dotum; font-size:12px;  text-indent:10px;}                                                                                                                                                                                             \n");
   			contentBase.append("				.td_01{ height:28px; background-color:#f5f9fe; line-height:28px; text-indent:20px; border-top:#cccccc solid 1px; border-right:#cccccc solid 1px; width:130px; font-weight:bold; color:#333333;}                                                                 \n");
   			contentBase.append("				.td_01_2{ height:28px; background-color:#f5f9fe; line-height:28px; text-indent:20px; border-top:#cccccc solid 1px; border-right:#cccccc solid 1px;border-bottom:#cccccc solid 1px; width:130px; font-weight:bold; color:#333333;}                               \n");
   			contentBase.append("				.td_02{ height:28px;line-height:28px;border-top:#cccccc solid 1px; text-indent:20px; font-weight:bold; color:#2f63ac;}                                                                                                                                          \n");
   			contentBase.append("				.td_02_2{ height:28px;line-height:28px; text-indent:5px; color:#2f63ac;}                                                                                                                                                                                        \n");
   			contentBase.append("				.td_02_3{ line-height:16px; color:#2f63ac; font-size:11px;}                                                                                                                                                                                                     \n");
   			contentBase.append("				.td_03{ height:300px;line-height:20px;border-top:#cccccc solid 1px; color:#333333; padding:20px;}                                                                                                                                                               \n");
   			contentBase.append("				.td_04{ height:28px;line-height:28px;border-top:#cccccc solid 1px; text-indent:20px; color:#666666;border-bottom:#cccccc solid 1px;}                                                                                                                            \n");
   			contentBase.append("				.text01{width:auto; font-size:12px; line-height:18px; padding:5px; text-align:left;}                                                                                                                                                                            \n");
   			contentBase.append("				.text_icon4{color:#ccc; font-size:12px; line-height:16px; width:15px; font-weight:bold;}                                                                                                                                                                        \n");
   			contentBase.append("				.style2 {                                                                                                                                                                                                                                                       \n");
   			contentBase.append("					font-size: 18px;                                                                                                                                                                                                                                            \n");
   			contentBase.append("					font-weight: bold;                                                                                                                                                                                                                                          \n");
   			contentBase.append("				}                                                                                                                                                                                                                                                               \n");
   			contentBase.append("				.style3 {font-size:12px; color:#3366CC; height:25px; text-align:left; vertical-align:top; text-indent:10px;}                                                                                                                                                    \n");
   			contentBase.append("				.style4 {color: #3366CC;font-weight: bold;font-size: 14px;}                                                                                                                                                                                                     \n");
   			contentBase.append("				</style>                                                                                                                                                                                                                                                        \n");
   			contentBase.append("				</head>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				<body style='padding:0px; margin:0px;'>                                                                                                                                                                                                                         \n");
   			contentBase.append("				<div align='center'>                                                                                                                                                                                                                                            \n");
   			contentBase.append("				 <table border='0' cellpadding='0' cellspacing='0' class='popup_table' style='width:800px; font-family:dotum; font-size:12px; color:#666666; text-align:left;'>                                                                                                                                                                                         \n");
   			contentBase.append("				  <tr>                                                                                                                                                                                                                                                          \n");
   			contentBase.append("				   <td>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				    <table border='0' cellpadding='0' cellspacing='0' style='width:800px; height:62px; background-image:url("+link+"/img/email/img_mail_title.gif); background-repeat:no-repeat;'>                                                                                             \n");
   			contentBase.append("				     <tr>                                                                                                                                                                                                                                                       \n");
   			contentBase.append("				      <td class='popup_logo'  width='232' style=' background-image:url("+link+"/img/email/popup_logo.gif) ; background-repeat:no-repeat; width:232px;'>&nbsp;</td>                                                                                                                                                                                                           \n");
   			contentBase.append("				      <td class='popup_title' style='font-family:dotum; font-size:12px;  text-indent:10px;'>"+subSubject+"</td>                                                                                                                                                                                                           		\n");
   			contentBase.append("				     </tr>                                                                                                                                                                                                                                                      \n");
   			contentBase.append("				    </table>                                                                                                                                                                                                                                                    \n");
   			contentBase.append("				   </td>                                                                                                                                                                                                                                                        \n");
   			contentBase.append("				  </tr>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				  <tr>                                                                                                                                                                                                                                                          \n");
   			contentBase.append("				    <td align='center' style='height:100%; padding:20px; background-image:url("+link+"/img/email/img_h_bg.gif); background-repeat:repeat-y;'>                                                                                                                                  \n");
   			contentBase.append("				     <table width='700' border='0' cellspacing='0' cellpadding='0'>                                                                                                                                                                                             \n");
   			contentBase.append("				        <tr>                                                                                                                                                                                                                                                    \n");
   			contentBase.append("				        <td height='50' align='center'  class='style1' style='color: #3366CC;font-weight: bold;font-size: 24px; border-bottom:#3366CC dotted 2px;'>"+subSubject+"</td>                                                                                                                                                                                       	\n");
   			contentBase.append("				       </tr>                                                                                                                                                                                                                                                    \n");
   			contentBase.append("				      <tr>                                                                                                                                                                                                                                                      \n");
   			contentBase.append("				        <td style='padding:30px 20px 20px 20px;'>                                                                                                                                                                                                               \n");
   			contentBase.append("				         <table width='98%' border='0' cellpadding='0' cellspacing='0' style='border:#CCCCCC dotted 1px;'>                                                                                                                                                      \n");
   			contentBase.append("				                 <tr>                                                                                                                                                                                                                                           \n");
   			contentBase.append("				                    <td height='20' colspan='3' style='line-height:24px; font-size:14px; font-weight:bold; text-align:left; padding:15px;'>구매테스트</td>                                                                                                                                                                                              \n");
   			contentBase.append("				                 </tr>                                                                                                                                                                                                                                          \n");
   			contentBase.append("				                 <tr>                                                                                                                                                                                                                                           \n");
   			contentBase.append("				                    <td height='20' colspan='3'>&nbsp;</td>                                                                                                                                                                                                     \n");
   			contentBase.append("				                 </tr>                                                                                                                                                                                                                                  		\n");
   			contentBase.append("				                 <tr>                                                                                                                                                                                                                                           \n");
   			contentBase.append("				                    <td height='20' colspan='3'>&nbsp;</td>                                                                                                                                                                                                     \n");
   			contentBase.append("				      			</tr>                                                                                                                                                                                                                                                     \n");
   			contentBase.append("				    	</table></td>                                                                                                                                                                                                                                               \n");
   			contentBase.append("				  		</tr>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				  		</table></td>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				  <tr>                                                                                                                                                                                                                                                          \n");
   			contentBase.append("				    <td align=center style='background-image:url("+link+"/img/email/img_h_bg.gif); background-repeat:repeat-y; padding-bottom:20px;'>                                                                                                                                        \n");
   			contentBase.append("				    <table border='0' cellspacing='0' cellpadding='0'>                                                                                                                                                                                                          \n");
   			contentBase.append("				      <tr>                                                                                                                                                                                                                                                      \n");
   			contentBase.append("				        <td><a href='"+linkPortal+"'><img src="+link+"/img/email/btn_go.gif alt='사이트접속하기' border='0'  /></a></td>                                                                                                                                                                  	\n");
   			contentBase.append("				      </tr>                                                                                                                                                                                                                                                     \n");
   			contentBase.append("				    </table></td>                                                                                                                                                                                                                                               \n");
   			contentBase.append("				  </tr>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				   <tr>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				    <td align='center' style='height:50px; vertical-align:top;'>                                                                                                                                                                                                \n");
   			contentBase.append("				    <table border='0' cellspacing='0' cellpadding='0'>                                                                                                                                                                                                          \n");
   			contentBase.append("				      <tr>                                                                                                                                                                                                                                                      \n");
   			contentBase.append("				        <td><img src="+link+"/img/email/img_mail_footter.jpg /></td>                                                                                                                                                                                                         \n");
   			contentBase.append("				      </tr>                                                                                                                                                                                                                                                     \n");
   			contentBase.append("				      <tr>                                                                                                                                                                                                                                                      \n");
   			contentBase.append("				        <td align='center' height='30' style='font-size:11px;'>본메일은 발신전용 메일이므로 회신되지 않습니다.</td>                                                                                                                                             				\n");
   			contentBase.append("				      </tr>                                                                                                                                                                                                                                                     \n");
   			contentBase.append("				                                                                                                                                                                                                                                                                \n");
   			contentBase.append("				    </table></td>                                                                                                                                                                                                                                               \n");
   			contentBase.append("				  </tr>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				 </table>                                                                                                                                                                                                                                                       \n");
   			contentBase.append("				</div>                                                                                                                                                                                                                                                          \n");
   			contentBase.append("				</body>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				</html>																																																															\n");
   		}else{
   			//외주
   			contentBase.append("				<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>																																		\n");
   			contentBase.append("				<html xmlns='http://www.w3.org/1999/xhtml'>                                                                                                                                                                                                                     \n");
   			contentBase.append("				<head>                                                                                                                                                                                                                                                          \n");
   			contentBase.append("				<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />                                                                                                                                                                                          \n");
   			contentBase.append("				<title>:::전자조달_mailing:::</title>                                                                                                                                                                                                                       	\n");
   			contentBase.append("				<style type='text/css'>                                                                                                                                                                                                                                         \n");
   			contentBase.append("				<!--                                                                                                                                                                                                                                                            \n");
   			contentBase.append("				.style1 {color: #3366CC;font-weight: bold;font-size: 24px; border-bottom:#3366CC dotted 2px;}                                                                                                                                                                   \n");
   			contentBase.append("				.popup_table{width:800px; font-family:dotum; font-size:12px; color:#666666; text-align:left;}                                                                                                                                                                   \n");
   			contentBase.append("				.text_red{font-size:12px; color:#cc0000; height:25px; text-align:left; vertical-align:top; text-indent:10px;}                                                                                                                                                   \n");
   			contentBase.append("				.popup_logo{ background-image:url("+link+"/img/email/popup_logo.gif) ; background-repeat:no-repeat; width:232px;}                                                                                                                                                              \n");
   			contentBase.append("				.popup_title{font-family:dotum; font-size:12px;  text-indent:10px;}                                                                                                                                                                                             \n");
   			contentBase.append("				.td_01{ height:28px; background-color:#f5f9fe; line-height:28px; text-indent:20px; border-top:#cccccc solid 1px; border-right:#cccccc solid 1px; width:130px; font-weight:bold; color:#333333;}                                                                 \n");
   			contentBase.append("				.td_01_2{ height:28px; background-color:#f5f9fe; line-height:28px; text-indent:20px; border-top:#cccccc solid 1px; border-right:#cccccc solid 1px;border-bottom:#cccccc solid 1px; width:130px; font-weight:bold; color:#333333;}                               \n");
   			contentBase.append("				.td_02{ height:28px;line-height:28px;border-top:#cccccc solid 1px; text-indent:20px; font-weight:bold; color:#2f63ac;}                                                                                                                                          \n");
   			contentBase.append("				.td_02_2{ height:28px;line-height:28px; text-indent:5px; color:#2f63ac;}                                                                                                                                                                                        \n");
   			contentBase.append("				.td_02_3{ line-height:16px; color:#2f63ac; font-size:11px;}                                                                                                                                                                                                     \n");
   			contentBase.append("				.td_03{ height:300px;line-height:20px;border-top:#cccccc solid 1px; color:#333333; padding:20px;}                                                                                                                                                               \n");
   			contentBase.append("				.td_04{ height:28px;line-height:28px;border-top:#cccccc solid 1px; text-indent:20px; color:#666666;border-bottom:#cccccc solid 1px;}                                                                                                                            \n");
   			contentBase.append("				.text01{width:auto; font-size:12px; line-height:18px; padding:5px; text-align:left;}                                                                                                                                                                            \n");
   			contentBase.append("				.text_icon4{color:#ccc; font-size:12px; line-height:16px; width:15px; font-weight:bold;}                                                                                                                                                                        \n");
   			contentBase.append("				.style2 {                                                                                                                                                                                                                                                       \n");
   			contentBase.append("					font-size: 18px;                                                                                                                                                                                                                                            \n");
   			contentBase.append("					font-weight: bold;                                                                                                                                                                                                                                          \n");
   			contentBase.append("				}                                                                                                                                                                                                                                                               \n");
   			contentBase.append("				.style3 {font-size:12px; color:#3366CC; height:25px; text-align:left; vertical-align:top; text-indent:10px;}                                                                                                                                                    \n");
   			contentBase.append("				.style4 {color: #3366CC;font-weight: bold;font-size: 14px;}                                                                                                                                                                                                     \n");
   			contentBase.append("				</style>                                                                                                                                                                                                                                                        \n");
   			contentBase.append("				</head>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				<body style='padding:0px; margin:0px;'>                                                                                                                                                                                                                         \n");
   			contentBase.append("				<div align='center'>                                                                                                                                                                                                                                            \n");
   			contentBase.append("				 <table border='0' cellpadding='0' cellspacing='0' class='popup_table' style='width:800px; font-family:dotum; font-size:12px; color:#666666; text-align:left;'>                                                                                                                                                                                         \n");
   			contentBase.append("				  <tr>                                                                                                                                                                                                                                                          \n");
   			contentBase.append("				   <td>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				    <table border='0' cellpadding='0' cellspacing='0' style='width:800px; height:62px; background-image:url("+link+"/img/email/img_mail_title2.gif); background-repeat:no-repeat;'>                                                                                             \n");
   			contentBase.append("				     <tr>                                                                                                                                                                                                                                                       \n");
   			contentBase.append("				      <td class='popup_logo'  width='232' style=' background-image:url("+link+"/img/email/popup_logo.gif) ; background-repeat:no-repeat; width:232px;'>&nbsp;</td>                                                                                                                                                                                                           \n");
   			contentBase.append("				      <td class='popup_title' style='font-family:dotum; font-size:12px;  text-indent:10px;'>"+subSubject+"</td>                                                                                                                                                                                                           		\n");
   			contentBase.append("				     </tr>                                                                                                                                                                                                                                                      \n");
   			contentBase.append("				    </table>                                                                                                                                                                                                                                                    \n");
   			contentBase.append("				   </td>                                                                                                                                                                                                                                                        \n");
   			contentBase.append("				  </tr>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				  <tr>                                                                                                                                                                                                                                                          \n");
   			contentBase.append("				    <td align='center' style='height:100%; padding:20px; background-image:url("+link+"/img/email/img_h_bg.gif); background-repeat:repeat-y;'>                                                                                                                                  \n");
   			contentBase.append("				     <table width='700' border='0' cellspacing='0' cellpadding='0'>                                                                                                                                                                                             \n");
   			contentBase.append("				        <tr>                                                                                                                                                                                                                                                    \n");
   			contentBase.append("				        <td height='50' align='center'  class='style1' style='color: #3366CC;font-weight: bold;font-size: 24px; border-bottom:#3366CC dotted 2px;'>"+subSubject+"</td>                                                                                                                                                                                       	\n");
   			contentBase.append("				       </tr>                                                                                                                                                                                                                                                    \n");
   			contentBase.append("				      <tr>                                                                                                                                                                                                                                                      \n");
   			contentBase.append("				        <td style='padding:30px 20px 20px 20px;'>                                                                                                                                                                                                               \n");
   			contentBase.append("				         <table width='98%' border='0' cellpadding='0' cellspacing='0' style='border:#CCCCCC dotted 1px;'>                                                                                                                                                      \n");
   			contentBase.append("				                 <tr>                                                                                                                                                                                                                                           \n");
   			contentBase.append("				                    <td height='20' colspan='3' style='line-height:24px; font-size:14px; font-weight:bold; text-align:left; padding:15px;'>외주테스트</td>                                                                                                                                                                                              \n");
   			contentBase.append("				                 </tr>                                                                                                                                                                                                                                          \n");
   			contentBase.append("				                 <tr>                                                                                                                                                                                                                                           \n");
   			contentBase.append("				                    <td height='20' colspan='3'>&nbsp;</td>                                                                                                                                                                                                     \n");
   			contentBase.append("				                 </tr>                                                                                                                                                                                                                                  		\n");
   			contentBase.append("				                 <tr>                                                                                                                                                                                                                                           \n");
   			contentBase.append("				                    <td height='20' colspan='3'>&nbsp;</td>                                                                                                                                                                                                     \n");
   			contentBase.append("				      			</tr>                                                                                                                                                                                                                                                     \n");
   			contentBase.append("				    	</table></td>                                                                                                                                                                                                                                               \n");
   			contentBase.append("				  		</tr>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				  		</table></td>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				  <tr>                                                                                                                                                                                                                                                          \n");
   			contentBase.append("				    <td align=center style='background-image:url("+link+"/img/email/img_h_bg.gif); background-repeat:repeat-y; padding-bottom:20px;'>                                                                                                                                        \n");
   			contentBase.append("				    <table border='0' cellspacing='0' cellpadding='0'>                                                                                                                                                                                                          \n");
   			contentBase.append("				      <tr>                                                                                                                                                                                                                                                      \n");
   			contentBase.append("				        <td><a href='"+linkPortal+"'><img src="+link+"/img/email/btn_go.gif alt='사이트접속하기' border='0'  /></a></td>                                                                                                                                                                  	\n");
   			contentBase.append("				      </tr>                                                                                                                                                                                                                                                     \n");
   			contentBase.append("				    </table></td>                                                                                                                                                                                                                                               \n");
   			contentBase.append("				  </tr>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				   <tr>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				    <td align='center' style='height:50px; vertical-align:top;'>                                                                                                                                                                                                \n");
   			contentBase.append("				    <table border='0' cellspacing='0' cellpadding='0'>                                                                                                                                                                                                          \n");
   			contentBase.append("				      <tr>                                                                                                                                                                                                                                                      \n");
   			contentBase.append("				        <td><img src="+link+"/img/email/img_mail_footter.jpg /></td>                                                                                                                                                                                                         \n");
   			contentBase.append("				      </tr>                                                                                                                                                                                                                                                     \n");
   			contentBase.append("				      <tr>                                                                                                                                                                                                                                                      \n");
   			contentBase.append("				        <td align='center' height='30' style='font-size:11px;'>본메일은 발신전용 메일이므로 회신되지 않습니다.</td>                                                                                                                                             				\n");
   			contentBase.append("				      </tr>                                                                                                                                                                                                                                                     \n");
   			contentBase.append("				                                                                                                                                                                                                                                                                \n");
   			contentBase.append("				    </table></td>                                                                                                                                                                                                                                               \n");
   			contentBase.append("				  </tr>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				 </table>                                                                                                                                                                                                                                                       \n");
   			contentBase.append("				</div>                                                                                                                                                                                                                                                          \n");
   			contentBase.append("				</body>                                                                                                                                                                                                                                                         \n");
   			contentBase.append("				</html>																																																															\n");
   		}

   		
   		try {
   			
   			Session session = Session.getInstance(properties, auth);				// Properties 객체와 auth(인증)객체로 메일전송 세션 생성
   			MimeMessage msg = new MimeMessage(session);								// 메일 객체를 세션을 통해 생성
   			
   			InternetAddress[] to_address = {new InternetAddress(toEmail)};			// 받는 사람 메일 주소 객체 생성
   		//	msg.setFrom(new InternetAddress(sendUser));							// 보내는 사람 메일주소 설정
   			
   			//msg.setFrom(new InternetAddress(sendUser, "SGC이앤씨(주)"));
   			msg.setFrom(new InternetAddress(new String(sendUser.getBytes("utf-8"), "8859_1")));							// 보내는 사람 메일주소 설정
   			

   			
   			msg.setRecipients(Message.RecipientType.TO, to_address);				// 받는 사람 메일 주소를 메일 객체에 매핑
   			msg.setContent(contentBase.toString(), "text/html; charset=utf-8");					// 메일 내용을 설정하며 메일 형식을 HTML로 지정
   			msg.setSubject(mailSubject,"utf-8");									// 메일 제목 설정
   			msg.setSentDate(new Date());											// 보내는 날짜 설정
   			
   			Transport.send(msg);													// 메일 전송 부분
   			
   		} catch(MessagingException me) {
   			 WAFLogger.error(this.getClass().getName() + " --> sendEmail() : \n" + me.getMessage());
   	         WAFLogger.error(me);
   			 throw me;
   		} catch(Exception e) {
   			WAFLogger.error(this.getClass().getName() + " --> sendEmail() : \n" + e.getMessage());
               WAFLogger.error(e);
               throw e;
   		}
   	}
    
   private RowSet getSmtpInfo() throws Exception{
       
   	Search search = new SearchImpl();
       RowSet rowSet = new RowSetImpl();
       
       StringBuffer sqlstr = new StringBuffer();       
       
       try {
       	sqlstr.append(" SELECT  CHG_CODE01             \n");
       	sqlstr.append("         ,CHG_CODE02            \n");
       	sqlstr.append("         ,CHG_CODE03            \n");
       	sqlstr.append("         ,CHG_CODE04            \n");
       	sqlstr.append("         ,CHG_CODE05            \n");
       	sqlstr.append("         ,CHG_CODE06            \n");
       	sqlstr.append(" FROM    EBID_COM910T A              \n");
       	sqlstr.append("         ,EBID_COM911T B             \n");
       	sqlstr.append(" WHERE   A.BASECD = B.BASECD    \n");
       	sqlstr.append(" AND     A.BASECD = 'EMAIL'     \n");
       	sqlstr.append(" AND     B.DETAILCD = '001'     \n");
       	
           search.setStatement(sqlstr.toString());
           rowSet = search.execute();            
       }
       catch(WAFSQLException se) {
           Logger.err.println("SQL : \n" + se.getStatement());
           Logger.err.println("PARAM : \n" + se.getParameter());
           throw se;
      }
       finally {
           if( rowSet == null ) rowSet = new RowSetImpl();
           return rowSet;
       }
   }
   
   
	
}