ITPub博客

首页 > 数据库 > Oracle > Oracle stored procedure to send email

Oracle stored procedure to send email

原创 Oracle 作者:zhyuh 时间:2004-10-10 10:55:21 0 删除 编辑

这是以前从网上看来的存储过程(很抱歉没记住原作者)。

在moto做项目时自己修改后测试了一下,真的好用,呵呵。可惜自己修改后的版本没有保留下来。 

[@more@]create or replace procedure ProcSendEmail(txt varchar2)         
IS                                                              
--sender's email address                                        
SendorAddress Varchar2(30) :=
'xxx@xxx.com';                    
--receiver 's email address                                     
ReceiverAddress varchar2(30) :=
'xxx@xxx.com';                  
--mail server's name or ip address                              
EmailServer varchar2(30) := '10.10.1.168';                      
Port number := 25;                                              
                                                                
conn UTL_SMTP.CONNECTION;                                       
crlf VARCHAR2( 2 ):= CHR( 13 ) || CHR( 10 );                    
contentmsg VARCHAR2( 60 ) := 'hello';                           
mesg VARCHAR2( 4000 );                                          
mesg_body varchar2(4000);                                       
BEGIN                                                           
                                                                
conn:= utl_smtp.open_connection( EmailServer, Port );           
utl_smtp.helo( conn, EmailServer );                             
utl_smtp.mail( conn, SendorAddress);                            
utl_smtp.rcpt( conn, ReceiverAddress );                         
                                                                
mesg:=                                                          
'Content-Type: text/plain; Charset=GB2312' || crlf ||           
'Date:' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf ||
'From:' || SendorAddress || crlf ||                             
'Subject: Sending Mail From Database' || crlf ||                
'To: '|| ReceiverAddress || crlf ||                             
'Content-Type: text/plain; Charset=GB2312' || crlf ||           
'' || crlf || txt || crlf ;                                     
                                                                
utl_smtp.data( conn, mesg );                                    
utl_smtp.quit( conn );                                          
                                                                
END;                                                             
                    

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/207/viewspace-779161/,如需转载,请注明出处,否则将追究法律责任。

上一篇: 国庆 -- 4. 捉虾
下一篇: Derek Wu
请登录后发表评论 登录
全部评论
  • 博文量
    233
  • 访问量
    2008767