Oracle存储过程中发邮件
Oracle存储过程中发邮件
Create or REPLACE PROCEDURE sp_send_mail( rcpter IN VARCHAR2, mail_content IN VARCHAR2) IS /**************************************************************************** parameter: Rcpter in varchar2 接收者邮箱 Mail_Content in Varchar2 邮件内容 desc: ·发送邮件到指定邮箱 ·只能指定一个邮箱,如果需要发送到多个邮箱,需要另外的辅助程序 ****************************************************************************/ conn utl_smtp.connection; --write title PROCEDURE send_header(NAME IN VARCHAR2, HEADER IN VARCHAR2) AS BEGIN utl_smtp.write_data(conn, NAME': ' HEADERutl_tcp.CRLF); END; BEGIN --opne connect conn := utl_smtp.open_connection('smtp.com'); utl_smtp.helo(conn, 'oracle'); utl_smtp.mail(conn, 'oracle info'); utl_smtp.rcpt(conn, Rcpter); utl_smtp.open_data(conn); --write title send_header('From', 'Oracle Database'); send_header('To', '"Recipient" <'rcpter'>'); send_header('Subject', 'DB Info'); --write mail content utl_smtp.write_data(conn, utl_tcp.crlf mail_content); --close connect utl_smtp.close_data(conn); utl_smtp.quit(conn); EXCEPTION WHEN utl_smtp.transient_error or utl_smtp.permanent_error THEN BEGIN utl_smtp.quit(conn); EXCEPTION WHEN OTHERS THEN NULL; END; WHEN OTHERS THEN NULL; END sp_send_mail;