1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| CREATE OR REPLACE PROCEDURE DBA_MONITOR_SEND_MAIL ( p_from IN VARCHAR2, p_to IN VARCHAR2, p_cc IN VARCHAR2 default null, p_bcc IN VARCHAR2 default null, p_reply IN VARCHAR2 default null, p_subject IN VARCHAR2, p_text IN VARCHAR2 default null, p_html in VARCHAR2 default null, p_smtp_hostname in varchar2, p_smtp_portnum in number, p_domain in varchar2 default null, p_login in varchar2, p_pwd in varchar2, p_html_body in clob ) IS --宣告 l_mail_conn UTL_SMTP.connection; l_boundary VARCHAR2(50) := '----=*#abc1234321cba#*=';
BEGIN --設定伺服器 l_mail_conn := UTL_SMTP.open_connection(p_smtp_hostname, p_smtp_portnum); --l_mail_conn := utl_smtp.open_connection('1.1.1.1', 25); UTL_SMTP.helo(l_mail_conn, p_smtp_hostname);
--寄件者 UTL_SMTP.mail(l_mail_conn, p_from);
--收件者 UTL_SMTP.rcpt(l_mail_conn, p_to); if p_cc is not null then UTL_SMTP.rcpt(l_mail_conn, p_cc); end if; UTL_SMTP.open_data(l_mail_conn);
-- 主旨 UTL_SMTP.write_data(l_mail_conn, 'From: ' || p_from || UTL_TCP.crlf); UTL_SMTP.write_data(l_mail_conn, 'To: ' || p_to || UTL_TCP.crlf); if p_cc is not null then UTL_SMTP.write_data(l_mail_conn, 'Cc: ' || p_cc || UTL_TCP.crlf); end if; UTL_smtp.write_raw_data(l_mail_conn, utl_raw.cast_to_raw( 'Subject: '|| p_subject || UTL_TCP.crlf)); UTL_SMTP.write_data(l_mail_conn, 'MIME-Version: 1.0' || UTL_TCP.crlf); UTL_SMTP.write_data(l_mail_conn, 'Content-Type: multipart/alternative; boundary="' || l_boundary || '"' || UTL_TCP.crlf || UTL_TCP.crlf); UTL_SMTP.write_data(l_mail_conn, '--' || l_boundary || UTL_TCP.crlf); UTL_SMTP.write_data(l_mail_conn, 'Content-Type: text/html; charset=utf-8/big5' || UTL_TCP.crlf || UTL_TCP.crlf); --utl_smtp.write_data( l_mail_conn, 'Content-Transfer-Encoding: 8bit' || UTL_TCP.crlf ); --UTL_smtp.write_raw_data(l_mail_conn, utl_raw.cast_to_raw( p_html_body )); UTL_smtp.write_raw_data(l_mail_conn, utl_raw.cast_to_raw(CONVERT(dbms_lob.substr(p_html_body), 'UTF8'))); UTL_SMTP.write_data(l_mail_conn, UTL_TCP.crlf || UTL_TCP.crlf); UTL_SMTP.write_data(l_mail_conn, '--' || l_boundary || '--' || UTL_TCP.crlf); UTL_SMTP.close_data(l_mail_conn); UTL_SMTP.quit(l_mail_conn); END; /
|