CREATE OR REPLACE PROCEDURE send_mail (
p_rec_email IN VARCHAR2,
p_message IN VARCHAR2,
p_subject IN VARCHAR2 DEFAULT ( xxxx'
|| TO_CHAR (SYSDATE,
'yyyy-mm-dd hh24:mi:ss'
)
),
p_sender IN VARCHAR2 DEFAULT ('ORACLE SYSTEM')
)
IS
v_mailhost VARCHAR2 (30) := xxxx.com';
mail_conn UTL_SMTP.connection;
msg VARCHAR2 (4000);
p_user VARCHAR2 (30) := 'domain\user';
p_pass VARCHAR2 (30) := '********';
BEGIN
msg :=
'Date:'
|| TO_CHAR (SYSDATE, 'dd mon yy hh24:mi:ss')
|| UTL_TCP.crlf
|| 'From: '
|| p_sender
|| '
|| p_sender
|| '>'
|| UTL_TCP.crlf
|| 'To: '
|| p_rec_email
|| '
|| p_rec_email
|| '>'
|| UTL_TCP.crlf
|| 'Subject: '
|| p_subject
|| UTL_TCP.crlf
|| UTL_TCP.crlf
|| p_message;
-- dbms_output.put_line(msg);
mail_conn := UTL_SMTP.open_connection (v_mailhost, '25');
UTL_SMTP.ehlo (mail_conn, v_mailhost);
UTL_SMTP.command (mail_conn, 'AUTH LOGIN');
UTL_SMTP.command
(mail_conn,
UTL_RAW.cast_to_varchar2
(UTL_ENCODE.base64_encode (UTL_RAW.cast_to_raw (p_user)
)
)
);
UTL_SMTP.command
(mail_conn,
UTL_RAW.cast_to_varchar2
(UTL_ENCODE.base64_encode (UTL_RAW.cast_to_raw (p_pass)
)
)
);
UTL_SMTP.mail (mail_conn, p_sender);
UTL_SMTP.rcpt (mail_conn, p_rec_email);
UTL_SMTP.DATA (mail_conn, msg);
UTL_SMTP.quit (mail_conn);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (DBMS_UTILITY.format_error_stack);
DBMS_OUTPUT.put_line (DBMS_UTILITY.format_call_stack);
END send_mail;
本人是个新手从坛子里找到了utl_smtp的使用方法,测试也通过了。(sql> 下),可用触发器如何调用?
create or replace trigger INSERT_MAIL
after insert or update ON table
FOR EACH ROW
begin
send_mail(p_rec_email => :new.user_email);
end;
报如下错误Compilation errors for TRIGGER DEVS.INSERT_MAIL
Error: PLS-00201: identifier 'SEND_MAIL' must be declared
Line: 7
Text: send_mail(p_rec_email => :new.user_email);
Error: PL/SQL: Statement ignored
Line: 7
Text: send_mail(p_rec_email => :new.user_email);
那位大侠帮帮忙,谢谢!
还有p_message如何加入好几列信息(同一行)