[Developer] Oracle send mail procedure(2)
CREATE OR REPLACE PACKAGE demo_base64 IS
FUNCTION encode(r IN RAW) RETURN VARCHAR2;
end;
CREATE OR REPLACE
PACKAGE BODY demo_base64 IS
TYPE vc2_table IS TABLE OF VARCHAR2(1) INDEX BY BINARY_INTEGER;
map vc2_table;
PROCEDURE init_map IS
BEGIN
map(0) :='A'; map(1) :='B'; map(2) :='C'; map(3) :='D'; map(4) :='E';
map(5) :='F'; map(6) :='G'; map(7) :='H'; map(8) :='I'; map(9):='J';
map(10):='K'; map(11):='L'; map(12):='M'; map(13):='N'; map(14):='O';
map(15):='P'; map(16):='Q'; map(17):='R'; map(18):='S'; map(19):='T';
map(20):='U'; map(21):='V'; map(22):='W'; map(23):='X'; map(24):='Y';
map(25):='Z'; map(26):='a'; map(27):='b'; map(28):='c'; map(29):='d';
map(30):='e'; map(31):='f'; map(32):='g'; map(33):='h'; map(34):='i';
map(35):='j'; map(36):='k'; map(37):='l'; map(38):='m'; map(39):='n';
map(40):='o'; map(41):='p'; map(42):='q'; map(43):='r'; map(44):='s';
map(45):='t'; map(46):='u'; map(47):='v'; map(48):='w'; map(49):='x';
map(50):='y'; map(51):='z'; map(52):='0'; map(53):='1'; map(54):='2';
map(55):='3'; map(56):='4'; map(57):='5'; map(58):='6'; map(59):='7';
map(60):='8'; map(61):='9'; map(62):='+'; map(63):='/';
END;
FUNCTION encode(r IN RAW) RETURN VARCHAR2 IS
i pls_integer;
x pls_integer;
y pls_integer;
v VARCHAR2(32767);
BEGIN
i := 1;
WHILE ( i + 2 <= utl_raw.length(r) ) LOOP
x := to_number(utl_raw.substr(r, i, 1), '0X') * 65536 +
to_number(utl_raw.substr(r, i + 1, 1), '0X') * 256 +
to_number(utl_raw.substr(r, i + 2, 1), '0X');
y := floor(x / 262144); v := v || map(y); x := x - y * 262144;
y := floor(x / 4096); v := v || map(y); x := x - y * 4096;
y := floor(x / 64); v := v || map(y); x := x - y * 64;
v := v || map(x);
i := i + 3;
END LOOP;
-- Process the remaining bytes that has fewer than 3 bytes.
IF ( utl_raw.length(r) - i = 0) THEN
x := to_number(utl_raw.substr(r, i, 1), '0X');
y := floor(x / 4); v := v || map(y); x := x - y * 4;
x := x * 16; v := v || map(x);
v := v || '==';
ELSIF ( utl_raw.length(r) - i = 1) THEN
x := to_number(utl_raw.substr(r, i, 1), '0X') * 256 +
to_number(utl_raw.substr(r, i + 1, 1), '0X');
y := floor(x / 1024); v := v || map(y); x := x - y * 1024;
y := floor(x / 16); v := v || map(y); x := x - y * 16;
x := x * 4; v := v || map(x);
v := v || '=';
END IF;
RETURN v;
END;
BEGIN
init_map;
END;
=============================================================================
CREATE OR REPLACE PROCEDURE sendmail(p_body in long, p_subject in varchar2)
is
p_sender varchar2(30) := 'automail@wlcsp.com';
-- p_subject varchar2(50) := 'Test';
mail_conn utl_smtp.connection;
mail_host varchar2(100) := 'smtp.wlcsp.com';
user_name varchar2(156) := 'automail@wlcsp.com';
user_pwd varchar2(156) := '1234qwer.';
M_EMAIL VARCHAR2(100);
cursor CUR_Email is select email from e_mail_address order by email;
begin
mail_conn := utl_smtp.open_connection(mail_host, 25);
utl_smtp.ehlo(mail_conn, mail_host);
utl_smtp.command(mail_conn, 'AUTH LOGIN');
utl_smtp.command(mail_conn, demo_base64.encode(utl_raw.cast_to_raw(user_name)));
utl_smtp.command(mail_conn, demo_base64.encode(utl_raw.cast_to_raw(user_pwd)));
--UTL_SMTP.command(mail_conn,UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode(UTL_RAW.cast_to_raw(user_name))));
--UTL_SMTP.command(mail_conn,UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode(UTL_RAW.cast_to_raw(user_pwd))));
utl_smtp.mail(mail_conn, '<' || p_sender || '>');
OPEN cur_Email;
LOOP
FETCH CUR_Email INTO M_EMAIL;
EXIT WHEN CUR_Email%NOTFOUND;
utl_smtp.rcpt(mail_conn, '<' || M_EMAIL || '>');
END LOOP;
CLOSE cur_Email;
utl_smtp.open_data(mail_conn);
utl_smtp.write_data(mail_conn,'Date:'|| TO_CHAR(SYSDATE, 'dd mon yy hh24:mi:ss') || utl_tcp.CRLF);
utl_smtp.write_data(mail_conn, 'From:' || p_sender ||'<' || p_sender || '>' || utl_tcp.CRLF);
utl_smtp.write_data(mail_conn, 'To:' || M_EMAIL ||'<' || M_EMAIL || '>' || utl_tcp.crlf);
utl_smtp.write_raw_data(mail_conn, utl_raw.cast_to_raw(convert('Subject:' || p_subject || utl_tcp.CRLF, 'ZHS16GBK')));
utl_smtp.write_raw_data(mail_conn, utl_raw.cast_to_raw(convert('Content-Type:text/html;charset=GBK' || utl_tcp.CRLF, 'ZHS16GBK')));
utl_smtp.write_data(mail_conn, utl_tcp.CRLF);
utl_smtp.write_raw_data(mail_conn, utl_raw.cast_to_raw(convert(p_body, 'ZHS16GBK')));
utl_smtp.close_data(mail_conn);
utl_smtp.quit(mail_conn);
exception
when utl_smtp.transient_error or utl_smtp.permanent_error then
utl_smtp.quit(mail_conn);
raise_application_error(-20000, sqlerrm);
when others then
raise_application_error(-20001, 'The send mail was error ' || sqlerrm);
end sendmail;
FUNCTION encode(r IN RAW) RETURN VARCHAR2;
end;
CREATE OR REPLACE
PACKAGE BODY demo_base64 IS
TYPE vc2_table IS TABLE OF VARCHAR2(1) INDEX BY BINARY_INTEGER;
map vc2_table;
PROCEDURE init_map IS
BEGIN
map(0) :='A'; map(1) :='B'; map(2) :='C'; map(3) :='D'; map(4) :='E';
map(5) :='F'; map(6) :='G'; map(7) :='H'; map(8) :='I'; map(9):='J';
map(10):='K'; map(11):='L'; map(12):='M'; map(13):='N'; map(14):='O';
map(15):='P'; map(16):='Q'; map(17):='R'; map(18):='S'; map(19):='T';
map(20):='U'; map(21):='V'; map(22):='W'; map(23):='X'; map(24):='Y';
map(25):='Z'; map(26):='a'; map(27):='b'; map(28):='c'; map(29):='d';
map(30):='e'; map(31):='f'; map(32):='g'; map(33):='h'; map(34):='i';
map(35):='j'; map(36):='k'; map(37):='l'; map(38):='m'; map(39):='n';
map(40):='o'; map(41):='p'; map(42):='q'; map(43):='r'; map(44):='s';
map(45):='t'; map(46):='u'; map(47):='v'; map(48):='w'; map(49):='x';
map(50):='y'; map(51):='z'; map(52):='0'; map(53):='1'; map(54):='2';
map(55):='3'; map(56):='4'; map(57):='5'; map(58):='6'; map(59):='7';
map(60):='8'; map(61):='9'; map(62):='+'; map(63):='/';
END;
FUNCTION encode(r IN RAW) RETURN VARCHAR2 IS
i pls_integer;
x pls_integer;
y pls_integer;
v VARCHAR2(32767);
BEGIN
i := 1;
WHILE ( i + 2 <= utl_raw.length(r) ) LOOP
x := to_number(utl_raw.substr(r, i, 1), '0X') * 65536 +
to_number(utl_raw.substr(r, i + 1, 1), '0X') * 256 +
to_number(utl_raw.substr(r, i + 2, 1), '0X');
y := floor(x / 262144); v := v || map(y); x := x - y * 262144;
y := floor(x / 4096); v := v || map(y); x := x - y * 4096;
y := floor(x / 64); v := v || map(y); x := x - y * 64;
v := v || map(x);
i := i + 3;
END LOOP;
-- Process the remaining bytes that has fewer than 3 bytes.
IF ( utl_raw.length(r) - i = 0) THEN
x := to_number(utl_raw.substr(r, i, 1), '0X');
y := floor(x / 4); v := v || map(y); x := x - y * 4;
x := x * 16; v := v || map(x);
v := v || '==';
ELSIF ( utl_raw.length(r) - i = 1) THEN
x := to_number(utl_raw.substr(r, i, 1), '0X') * 256 +
to_number(utl_raw.substr(r, i + 1, 1), '0X');
y := floor(x / 1024); v := v || map(y); x := x - y * 1024;
y := floor(x / 16); v := v || map(y); x := x - y * 16;
x := x * 4; v := v || map(x);
v := v || '=';
END IF;
RETURN v;
END;
BEGIN
init_map;
END;
=============================================================================
CREATE OR REPLACE PROCEDURE sendmail(p_body in long, p_subject in varchar2)
is
p_sender varchar2(30) := 'automail@wlcsp.com';
-- p_subject varchar2(50) := 'Test';
mail_conn utl_smtp.connection;
mail_host varchar2(100) := 'smtp.wlcsp.com';
user_name varchar2(156) := 'automail@wlcsp.com';
user_pwd varchar2(156) := '1234qwer.';
M_EMAIL VARCHAR2(100);
cursor CUR_Email is select email from e_mail_address order by email;
begin
mail_conn := utl_smtp.open_connection(mail_host, 25);
utl_smtp.ehlo(mail_conn, mail_host);
utl_smtp.command(mail_conn, 'AUTH LOGIN');
utl_smtp.command(mail_conn, demo_base64.encode(utl_raw.cast_to_raw(user_name)));
utl_smtp.command(mail_conn, demo_base64.encode(utl_raw.cast_to_raw(user_pwd)));
--UTL_SMTP.command(mail_conn,UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode(UTL_RAW.cast_to_raw(user_name))));
--UTL_SMTP.command(mail_conn,UTL_RAW.cast_to_varchar2(UTL_ENCODE.base64_encode(UTL_RAW.cast_to_raw(user_pwd))));
utl_smtp.mail(mail_conn, '<' || p_sender || '>');
OPEN cur_Email;
LOOP
FETCH CUR_Email INTO M_EMAIL;
EXIT WHEN CUR_Email%NOTFOUND;
utl_smtp.rcpt(mail_conn, '<' || M_EMAIL || '>');
END LOOP;
CLOSE cur_Email;
utl_smtp.open_data(mail_conn);
utl_smtp.write_data(mail_conn,'Date:'|| TO_CHAR(SYSDATE, 'dd mon yy hh24:mi:ss') || utl_tcp.CRLF);
utl_smtp.write_data(mail_conn, 'From:' || p_sender ||'<' || p_sender || '>' || utl_tcp.CRLF);
utl_smtp.write_data(mail_conn, 'To:' || M_EMAIL ||'<' || M_EMAIL || '>' || utl_tcp.crlf);
utl_smtp.write_raw_data(mail_conn, utl_raw.cast_to_raw(convert('Subject:' || p_subject || utl_tcp.CRLF, 'ZHS16GBK')));
utl_smtp.write_raw_data(mail_conn, utl_raw.cast_to_raw(convert('Content-Type:text/html;charset=GBK' || utl_tcp.CRLF, 'ZHS16GBK')));
utl_smtp.write_data(mail_conn, utl_tcp.CRLF);
utl_smtp.write_raw_data(mail_conn, utl_raw.cast_to_raw(convert(p_body, 'ZHS16GBK')));
utl_smtp.close_data(mail_conn);
utl_smtp.quit(mail_conn);
exception
when utl_smtp.transient_error or utl_smtp.permanent_error then
utl_smtp.quit(mail_conn);
raise_application_error(-20000, sqlerrm);
when others then
raise_application_error(-20001, 'The send mail was error ' || sqlerrm);
end sendmail;
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-2074748/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- oracle send mailOracleAI
- Send MailAI
- [原創]How to send patch files by git send-mailGitAI
- Send E-mail with PDF attachment using Node.jsAINode.js
- Others_2_MailAI
- 使用Oracle SQL Developer匯入Excel資料OracleSQLDeveloperExcel
- 【Oracle】常用工具-oracle sql developer快速安裝使用教程OracleSQLDeveloper
- 「Oracle」客戶端 PL/SQL DEVELOPER 安裝使用Oracle客戶端SQLDeveloper
- PL/SQL Developer連線到Oracle 12cSQLDeveloperOracle
- 【ASK_ORACLE】Oracle RAC報錯“ipc send timeout”的原因以及解決辦法Oracle
- XMLHttpRequest send()XMLHTTP
- Procedure to create Distribution model
- Sampling Procedure 和 Sample-drawing Procedure,SAP QM裡的雙胞胎?
- PL/SQL Developer連線遠端Oracle資料庫SQLDeveloperOracle資料庫
- os ,shutil,send2trash模組彙總(tcy)
- You have new mail in /var/spool/mail/rootAI
- 5. Oracle連線和使用——5.2. PL/SQL DeveloperOracleSQLDeveloper
- 本地不安裝oracle,用PL/SQL Developer連線資料庫OracleSQLDeveloper資料庫
- PostgreSQL/LightDB- Tried to send an out-of-range integer as a 2-byte valueSQL
- pl developerDeveloper
- nagios mail告警通知iOSAI
- xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)ErrorDeveloper
- 用ffsend使用Firefox SendFirefox
- Oracle SQL Developer 連線資料庫總是顯示io錯誤OracleSQLDeveloper資料庫
- Mysql關於procedure、function的詳解MySqlFunction
- stored procedure 收集session wait 資訊(轉)SessionAI
- PLSQL Developer 14SQLDeveloper
- golang mail、shell、cookie、uuidGolangAICookieUI
- Fedora 中如何使用 Firefox Send?Firefox
- mysql 儲存過程 procedure 批次建表MySql儲存過程
- mybatis3呼叫瀚高procedure報錯MyBatisS3
- PLSQL Developer 行號SQLDeveloper
- PLSQL Developer配置使用SQLDeveloper
- 生成器yield,next()與send()
- oracle event 2 (zt)Oracle
- mysql檢視儲存過程show procedure status;MySql儲存過程
- Spring 呼叫 Stored Procedure 並獲取返回值Spring
- Oracle vs PostgreSQL DBA(22)- Oracle VPD#2OracleSQL
- Linux之郵件mail服務LinuxAI