oracle utl_smtp 500 bad syntax,UTL_MAIL发送失败,求助

以前不知道哪里抄来的程序,用的是utl_smtp:

create or replace package mail_pkg

as

type array is table of varchar2(255);

procedure send( p_sender_email in varchar2,

p_from         in varchar2,

p_to           in array default array(),

p_cc           in array default array(),

p_bcc          in array default array(),

p_subject      in varchar2,

p_body         in long );

end mail_pkg;

/

create or replace package body mail_pkg

as

g_crlf        char(2) default chr(13)||chr(10);

g_mail_conn   utl_smtp.connection;

g_mailhost    varchar2(255) := 'aria.us.oracle.com';

function address_email( p_string in varchar2,

p_recipients in array ) return varchar2

is

l_recipients long;

begin

for i in 1 .. p_recipients.count

loop

utl_smtp.rcpt(g_mail_conn, p_recipients(i) );

if ( l_recipients is null )

then

l_recipients := p_string || p_recipients(i) ;

else

l_recipients := l_recipients || ', ' || p_recipients(i);

end if;

end loop;

return l_recipients;

end;

procedure send( p_sender_email in varchar2,

p_from         in varchar2 default NULL,

p_to           in array default array(),

p_cc           in array default array(),

p_bcc          in array default array(),

p_subject      in varchar2 default NULL,

p_body         in long  default NULL )

is

l_to_list   long;

l_cc_list   long;

l_bcc_list  long;

l_date      varchar2(255) default

to_char( SYSDATE, 'dd Mon yy hh24:mi:ss' );

procedure writeData( p_text in varchar2 )

as

begin

if ( p_text is not null )

then

utl_smtp.write_data( g_mail_conn, p_text || g_crlf );

end if;

end;

begin

g_mail_conn := utl_smtp.open_connection(g_mailhost, 25);

utl_smtp.helo(g_mail_conn, g_mailhost);

utl_smtp.mail(g_mail_conn, p_sender_email);

l_to_list  := address_email( 'To: ', p_to );

l_cc_list  := address_email( 'Cc: ', p_cc );

l_bcc_list := address_email( 'Bcc: ', p_bcc );

utl_smtp.open_data(g_mail_conn );

writeData( 'Date: ' || l_date );

writeData( 'From: ' || nvl( p_from, p_sender_email ) );

writeData( 'Subject: ' || nvl( p_subject, '(no subject)' ) );

writeData( l_to_list );

writeData( l_cc_list );

utl_smtp.write_data( g_mail_conn, '' || g_crlf );

utl_smtp.write_data(g_mail_conn, p_body );

utl_smtp.close_data(g_mail_conn );

utl_smtp.quit(g_mail_conn);

end;

end mail_pkg;

/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值