时间:2021-05-02
在Procedure中p_receiver为收件人地址,多收件人以“,”(英文逗号)分割,
p_sub为邮件标题,p_txt为邮件内容(支持HTML)。代码如下:
复制代码 代码如下:
create or replace procedure bsd_sendemail (p_receiver varchar2,p_sub varchar2,p_txt varchar2)
is
p_user varchar2(30) := '';
p_pass varchar2(30) := '';
p_sendor varchar2(20) := 'Gnie';
p_server varchar2(20) := 'Mail_Server_IP';
p_port number := 25;
p_need_smtp number := 0;
p_subject varchar2(4000);
l_crlf varchar2(2) := utl_tcp.crlf;
l_sendoraddress varchar2(4000);
l_splite varchar2(10) := '++';
boundary constant varchar2(256) := '-----BYSUK';
first_boundary constant varchar2(256) := '--' || boundary || l_crlf;
last_boundary constant varchar2(256) := '--' || boundary || '--' || l_crlf;
multipart_mime_type constant varchar2(256) := 'multipart/mixed; boundary="' || boundary || '"';
type address_list is table of varchar2(100) index by binary_integer;
my_address_list address_list;
---------------------------------------分割邮件地址----------------------------------------------
procedure p_splite_str(p_str varchar2,p_splite_flag int default 1) is
l_addr varchar2(254) := '';
l_len int;
l_str varchar2(4000);
j int := 0; --表示邮件地址或者附件的个数
begin
l_str := trim(rtrim(replace(replace(p_str, ';', ','), ' ', ''), ','));
l_len := length(l_str);
for i in 1 .. l_len loop
if substr(l_str, i, 1) <> ',' then
l_addr := l_addr || substr(l_str, i, 1);
else
j := j + 1;
if p_splite_flag = 1 then --表示处理邮件地址
--前后需要加上'<>',否则很多邮箱将不能发送邮件
l_addr := '<' || l_addr || '>';
--调用邮件发送过程
my_address_list(j) := l_addr;
end if;
l_addr := '';
end if;
if i = l_len then
j := j + 1;
if p_splite_flag = 1 then
--调用邮件发送过程
l_addr := '<' || l_addr || '>';
my_address_list(j) := l_addr;
end if;
end if;
end loop;
end;
------------------------------------------------写邮件头和邮件内容------------------------------------------
procedure write_data(p_conn in out nocopy utl_smtp.connection,
p_name in varchar2,
p_value in varchar2,
p_splite varchar2 default ':',
p_crlf varchar2 default l_crlf) is
begin
utl_smtp.write_raw_data(p_conn, utl_raw.cast_to_raw(convert(p_name||p_splite||p_value ||p_crlf, 'ZHS16CGB231280')));
end;
----------------------------------------写mime邮件尾部-----------------------------------------------------
procedure end_boundary(conn in out nocopy utl_smtp.connection, last in boolean default false) is
begin
utl_smtp.write_data(conn, utl_tcp.crlf);
if (last) then
utl_smtp.write_data(conn, last_boundary);
end if;
end;
---------------------------------------------真正发送邮件的过程--------------------------------------------
procedure p_email(p_sendoraddress2 varchar2, --发送地址
p_receiveraddress2 varchar2) --接受地址
is
l_conn utl_smtp.connection; --定义连接
begin
l_conn := utl_smtp.open_connection(p_server, p_port);
utl_smtp.helo(l_conn, p_server);
if p_need_smtp = 1 then
utl_smtp.command(l_conn, 'AUTH LOGIN', '');
utl_smtp.command(l_conn, utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(p_user))));
utl_smtp.command(l_conn, utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_raw.cast_to_raw(p_pass))));
end if;
utl_smtp.mail(l_conn, p_sendoraddress2);
utl_smtp.rcpt(l_conn, p_receiveraddress2);
utl_smtp.open_data(l_conn);
--write_data(l_conn, 'Date', to_char(sysdate-1/3, 'dd Mon yy hh24:mi:ss'));
write_data(l_conn, 'From', p_sendor);
write_data(l_conn, 'To', p_receiver);
select replace('=?GB2312?B?'||utl_raw.cast_to_varchar2(utl_encode.base64_encode(rawtohex(p_sub)))||'?=',utl_tcp.crlf,'')
into p_subject from dual;
write_data(l_conn, 'Subject', p_subject);
write_data(l_conn, 'Content-Type', multipart_mime_type);
utl_smtp.write_data(l_conn, utl_tcp.crlf);
utl_smtp.write_data(l_conn, first_boundary);
write_data(l_conn, 'Content-Type', 'text/html;charset=gb2312');
--单独空一行,否则,正文内容不显示
utl_smtp.write_data(l_conn, utl_tcp.crlf);
write_data(l_conn, '', replace(replace(p_txt, l_splite, chr(10)), chr(10), l_crlf), '', '');
end_boundary(l_conn);
utl_smtp.close_data(l_conn);
utl_smtp.quit(l_conn);
end;
---------------------------------------------主过程-----------------------------------------------------
begin
l_sendoraddress := '<' || p_sendor || '>';
p_splite_str(p_receiver);--处理邮件地址
for k in 1 .. my_address_list.count loop
p_email(l_sendoraddress, my_address_list(k));
end loop;
end;
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
为大家准备的win7下oracle10g安装图解教程,非常详细:方法/步骤Oracle10g安装预备步骤取得Oracle10g安装程序,或从Oracle技术网(
win7下安装oracle10g服务端和客户端方法如下所示:如何卸载Oracle10g软件环境:1、WindowsXP+Oracle10g2、Oracle安装路
oracle10g卸载 软件环境: 1、WindowsXP+Oracle10g 2、Oracle安装路径为:d:\Oracle 实现方法: 1、开始-
一、Oracle11g安装安装之前要先确定自己的电脑配置,以windows为例,如果是win7以下系统如xp等,可以选择Oracle10g。因为10g的程序文件
如何重置oracle10gSYS的密码安装完oracle10g后,竟然将安装时设置的系统密码忘记。在同事的帮助下通过一下方法解决。1.oracle的密码文件存在