Oracle stored procedure to send email

zhyuh發表於2004-10-10

這是以前從網上看來的儲存過程(很抱歉沒記住原作者)。

在moto做專案時自己修改後測試了一下,真的好用,呵呵。可惜自己修改後的版本沒有保留下來。 

[@more@]create or replace procedure ProcSendEmail(txt varchar2)         
IS                                                              
--sender's email address                                        
SendorAddress Varchar2(30) :=
;                    
--receiver 's email address                                     
ReceiverAddress varchar2(30) :=
;                  
--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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章