create or replace procedure test
is
--SMTP and TCP/IP 连接信息
conn utl_smtp.connection;
--返回信息
v_reply UTL_SMTP.REPLY;
--发送mail所显示的头信息
procedure send_header(ctx in varchar2) as
begin
utl_smtp.write_data(conn, ctx||utl_tcp.CRLF);
end;
begin
conn := utl_smtp.open_connection('192.100.2.192');
v_reply := utl_smtp.helo(conn, '192.100.2.192');
dbms_output.put_line(v_reply.code||' helo reply '||v_reply.text);
v_reply := utl_smtp.mail(conn, 'guoxh');
dbms_output.put_line(v_reply.code||' mail reply '||v_reply.text);
v_reply := utl_smtp.rcpt(conn, 'guoxh');
dbms_output.put_line(v_reply.code||' rcpt reply '||v_reply.text);
utl_smtp.open_data(conn);
--write title
dbms_output.put_line('write title');
send_header('From: master');
send_header('To: "Guoxh" <GuoXianHua>');
send_header('Subject: DB Info');
--write mail content
dbms_output.put_line('write mail content');
--支持中文发送
UTL_SMTP.WRITE_RAW_DATA(conn,UTL_RAW.CAST_TO_RAW(UTL_TCP.CRLF||'Hi, I''m coming from the oracle9i中国'));
--utl_smtp.write_data(conn, utl_tcp.crlf || 'Hi, I''m coming from the oracle9i中国');
--close connect
utl_smtp.close_data(conn);
utl_smtp.quit(conn);
EXCEPTION
WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
BEGIN
dbms_output.put_line('smtp error: '||SQLERRM);
utl_smtp.quit(conn);
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('other error');
END;
WHEN OTHERS THEN
NULL;
end test;
is
--SMTP and TCP/IP 连接信息
conn utl_smtp.connection;
--返回信息
v_reply UTL_SMTP.REPLY;
--发送mail所显示的头信息
procedure send_header(ctx in varchar2) as
begin
utl_smtp.write_data(conn, ctx||utl_tcp.CRLF);
end;
begin
conn := utl_smtp.open_connection('192.100.2.192');
v_reply := utl_smtp.helo(conn, '192.100.2.192');
dbms_output.put_line(v_reply.code||' helo reply '||v_reply.text);
v_reply := utl_smtp.mail(conn, 'guoxh');
dbms_output.put_line(v_reply.code||' mail reply '||v_reply.text);
v_reply := utl_smtp.rcpt(conn, 'guoxh');
dbms_output.put_line(v_reply.code||' rcpt reply '||v_reply.text);
utl_smtp.open_data(conn);
--write title
dbms_output.put_line('write title');
send_header('From: master');
send_header('To: "Guoxh" <GuoXianHua>');
send_header('Subject: DB Info');
--write mail content
dbms_output.put_line('write mail content');
--支持中文发送
UTL_SMTP.WRITE_RAW_DATA(conn,UTL_RAW.CAST_TO_RAW(UTL_TCP.CRLF||'Hi, I''m coming from the oracle9i中国'));
--utl_smtp.write_data(conn, utl_tcp.crlf || 'Hi, I''m coming from the oracle9i中国');
--close connect
utl_smtp.close_data(conn);
utl_smtp.quit(conn);
EXCEPTION
WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
BEGIN
dbms_output.put_line('smtp error: '||SQLERRM);
utl_smtp.quit(conn);
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('other error');
END;
WHEN OTHERS THEN
NULL;
end test;