Thứ Hai, 30 tháng 11, 2020

Thủ tục gửi email trong Oracle Database

CREATE OR REPLACE 
PROCEDURE send_email_html (str_to        IN VARCHAR2,
                      str_subject   IN VARCHAR2,
                      str_body      IN VARCHAR2)
IS
    l_mail_conn   UTL_SMTP.connection;
BEGIN
    
    l_mail_conn := UTL_SMTP.open_connection ('10.10.10.10', 25);
    UTL_SMTP.helo (l_mail_conn, '10.10.10.10');
    UTL_SMTP.command (l_mail_conn, 'AUTH LOGIN');
    UTL_SMTP.command (
        l_mail_conn,
        UTL_RAW.cast_to_varchar2 (
            UTL_ENCODE.base64_encode (UTL_RAW.cast_to_raw ('test'))));
    UTL_SMTP.command (
        l_mail_conn,
        UTL_RAW.cast_to_varchar2 (
            UTL_ENCODE.base64_encode (UTL_RAW.cast_to_raw ('abcd%1234'))));
    UTL_SMTP.mail (l_mail_conn, 'test@xxx.com');
    UTL_SMTP.rcpt (l_mail_conn, str_to);
    UTL_SMTP.open_data (l_mail_conn);
    UTL_SMTP.write_data (
        l_mail_conn,
        'Subject: =?UTF-8?Q?'
        || UTL_RAW.cast_to_varchar2(UTL_ENCODE.quoted_printable_encode (
                                        UTL_RAW.cast_to_raw (str_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: text/html;charset=utf-8' || UTL_TCP.crlf);
    UTL_SMTP.write_data (
        l_mail_conn,
        'Content-Transfer-Encoding: quoted-printable ' || UTL_TCP.crlf);

    UTL_SMTP.write_data (
        l_mail_conn,
           'Date: '
        || TO_CHAR (SYSDATE, 'DD-MON-YYYY HH24:MI:SS')
        || UTL_TCP.crlf);
    UTL_SMTP.write_data (l_mail_conn, 'To: ' || str_to || UTL_TCP.crlf);
    UTL_SMTP.write_data (
        l_mail_conn,
        'From: ' || 'SystemAlerter@xxx.com' || UTL_TCP.crlf);

    UTL_SMTP.write_data (
        l_mail_conn,
           'Reply-To: '
        || 'test@xxx.com'
        || UTL_TCP.crlf
        || UTL_TCP.crlf);

    UTL_SMTP.write_raw_data (
        l_mail_conn,
        UTL_ENCODE.quoted_printable_encode (UTL_RAW.cast_to_raw (str_body)));

    UTL_SMTP.close_data (l_mail_conn);

    UTL_SMTP.quit (l_mail_conn);
END send_email_html;
/



KẾT NỐI VỚI CHUYÊN GIA TRẦN VĂN BÌNH: 📧 Mail: binhoracle@gmail.com ☎️ Mobile: 0902912888 ⚡️ Skype: tranbinh48ca 👨 Facebook: https://www.facebook.com/BinhOracleMaster 👨 Inbox Messenger: https://m.me/101036604657441 (profile) 👨 Fanpage: https://www.facebook.com/tranvanbinh.vn 👨 Inbox Fanpage: https://m.me/tranvanbinh.vn 👨👩 Group FB: https://www.facebook.com/groups/OracleDBAVietNam 👨 Website: http://www.tranvanbinh.vn 👨 Blogger: https://tranvanbinhmaster.blogspot.com 🎬 Youtube: http://bit.ly/ytb_binhoraclemaster 👨 Tiktok: https://www.tiktok.com/@binhoraclemaster?lang=vi 👨 Linkin: https://www.linkedin.com/in/binhoracle 👨 Twitter: https://twitter.com/binhoracle 👨 Địa chỉ: Tòa nhà Sun Square - 21 Lê Đức Thọ - Phường Mỹ Đình 1 - Quận Nam Từ Liêm - TP.Hà Nội #OracleTutorial #OracleDBA #OracleDatabaseAdministration #học oracle database #oca #ocp #oce #ocm

ĐỌC NHIỀU

Trần Văn Bình - Oracle Database Master