today:
434
yesterday:
719
Total:
1,770,218

Technology

SENDING EMAIL PROCEDURE

admin 2018.10.08 04:42 Views : 273

CREATE OR REPLACE PROCEDURE UP_SEND_MAIL(
    V_SUBJECT IN VARCHAR2,
    V_BODY IN VARCHAR2,
    V_S_MAIL IN VARCHAR2,
    V_R_MAIL IN VARCHAR2 ,
    V_RETURN OUT NUMBER
)
/*
*  DESCRIPTION
*      메일 전송
*  PARAMETER
*      V_SUBJECT : 제목
*      V_BODY    : 본문
*      V_S_MAIL  : 발신메일
*      V_R_MAIL  : 수신메일
*/
    IS
        MAIL_CONN       utl_smtp.connection;
        T_BODY          VARCHAR2(3999);
        SEND_MAIL       VARCHAR2(100);
        RCPT_MAIL       VARCHAR2(2000);
BEGIN
    DBMS_OUTPUT.PUT_LINE('메일발송처리 시작');
    DBMS_OUTPUT.PUT_LINE(V_SUBJECT || '   ' || V_BODY || '   ' || V_S_MAIL|| '   ' || V_R_MAIL);       
           
    SEND_MAIL := V_S_MAIL;  --발신메일
    RCPT_MAIL := V_R_MAIL;  --수신메일  
     
    MAIL_CONN := UTL_SMTP.OPEN_CONNECTION('0.0.0.0',25);
    UTL_SMTP.HELO(MAIL_CONN, '0.0.0.0');          --MAIL HOST
    UTL_SMTP.MAIL(MAIL_CONN, SEND_MAIL);                 --발신메일
     
    --','를 구분자로 하여 수신자메일 SPLIT 처리
    FOR V_ROW_REC IN (
                      SELECT TRIM(COLUMN_VALUE) AS I_REC_MAIL                           
                        FROM TABLE (RDMS_SPLIT(RCPT_MAIL, ','))
                      )
    LOOP
         
        IF TRIM(V_ROW_REC.I_REC_MAIL) IS NOT NULL THEN
            --DBMS_OUTPUT.PUT_LINE('수신메일:'||V_ROW_REC.I_REC_MAIL);
             
            UTL_SMTP.RCPT(MAIL_CONN, V_ROW_REC.I_REC_MAIL); --수신메일
        END IF;
                        
    END LOOP;
     
    T_BODY := T_BODY || 'Subject : ' || V_SUBJECT || UTL_TCP.crlf;   
    T_BODY := T_BODY || '';
    T_BODY := T_BODY || V_BODY;
     
    UTL_SMTP.OPEN_DATA(MAIL_CONN);                       --data open
    UTL_SMTP.WRITE_DATA (MAIL_CONN,'MIME-version: 1.0' || UTL_TCP.crlf);
    UTL_SMTP.WRITE_DATA (MAIL_CONN,'Content-Type: text/html; charset=ks_c_5601-1987'|| UTL_TCP.crlf);
     
    UTL_SMTP.WRITE_RAW_DATA(MAIL_CONN, UTL_RAW.CAST_TO_RAW(T_BODY));
    UTL_SMTP.CLOSE_DATA(MAIL_CONN);
    UTL_SMTP.QUIT(MAIL_CONN);
     
    V_RETURN := 0;
EXCEPTION WHEN OTHERS THEN
    V_RETURN := 1;
    RETURN;
END;