CREATE OR REPLACE PROCEDURE SYSTEM.SEND_EMAIL
( sender IN VARCHAR2,
recipient IN VARCHAR2,
subject IN VARCHAR2,
message IN VARCHAR2)
AS
mailhost VARCHAR2(100) := 'webmail.xxx.zzz';
mail_conn utl_smtp.connection;
BEGIN
mail_conn :=utl_smtp.open_connection(mailhost,25);
utl_smtp.helo(mail_conn,mailhost);
utl_smtp.mail(mail_conn,sender); -- sender
utl_smtp.rcpt(mail_conn,recipient); -- recipient
utl_smtp.open_data(mail_conn);
utl_smtp.write_data(mail_conn,'FROM : <'||sender||'>'||utl_tcp.CRLF);
utl_smtp.write_data(mail_conn,'To : <'||recipient||'>'||utl_tcp.CRLF);
utl_smtp.write_data(mail_conn,'Subject: '|| subject);
utl_smtp.write_data(mail_conn, utl_tcp.CRLF||message);
utl_smtp.close_data(mail_conn);
utl_smtp.quit(mail_conn);
EXCEPTION
WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
utl_smtp.quit(mail_conn);
raise_application_error(-20000,
'Failed tosend mail due to the following error: ' || sqlerrm);
WHEN OTHERS THEN
raise_application_error(-20001,
'The following error has occured: ' || sqlerrm);
END;
/