CREATE OR REPLACE PROCEDURE common_text_email_prc (
p_from_mail IN VARCHAR2,
p_to_mail IN VARCHAR2,
p_subject IN VARCHAR2,
p_message IN VARCHAR2,
p_host_name IN VARCHAR2
)
IS
l_mail_conn UTL_SMTP.connection;
l_count NUMBER;
CURSOR email_cur
IS
SELECT LIST.tml emails
FROM (WITH xhl_email_list_rec AS
(SELECT p_to_mail tml
FROM DUAL)
SELECT REGEXP_SUBSTR (tml, '[^,]+', 1, LEVEL) tml
FROM xhl_email_list_rec
CONNECT BY LEVEL <= (SELECT LENGTH (REPLACE (tml, ',', NULL))
FROM xhl_email_list_rec)) LIST
WHERE LIST.tml IS NOT NULL;
BEGIN
l_mail_conn := UTL_SMTP.open_connection (p_host_name);
UTL_SMTP.helo (l_mail_conn, p_host_name);
UTL_SMTP.mail (l_mail_conn, p_from_mail);
FOR email_rec IN email_cur
LOOP
UTL_SMTP.rcpt (l_mail_conn, email_rec.emails);
END LOOP;
UTL_SMTP.open_data (l_mail_conn);
UTL_SMTP.write_data (l_mail_conn, 'From: ' || p_from_mail || UTL_TCP.crlf);
UTL_SMTP.write_data (l_mail_conn, 'Subject: ' || p_subject || UTL_TCP.crlf);
UTL_SMTP.write_data (l_mail_conn, 'To: ' || p_to_mail || UTL_TCP.crlf);
UTL_SMTP.write_data (l_mail_conn, p_message);
UTL_SMTP.close_data (l_mail_conn);
UTL_SMTP.quit (l_mail_conn);
DBMS_OUTPUT.put_line ('Mail sent successfully');
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ( 'Exception in send_mail'
|| SUBSTR (SQLERRM, 1, 200)
);
END common_text_email_prc;
p_from_mail IN VARCHAR2,
p_to_mail IN VARCHAR2,
p_subject IN VARCHAR2,
p_message IN VARCHAR2,
p_host_name IN VARCHAR2
)
IS
l_mail_conn UTL_SMTP.connection;
l_count NUMBER;
CURSOR email_cur
IS
SELECT LIST.tml emails
FROM (WITH xhl_email_list_rec AS
(SELECT p_to_mail tml
FROM DUAL)
SELECT REGEXP_SUBSTR (tml, '[^,]+', 1, LEVEL) tml
FROM xhl_email_list_rec
CONNECT BY LEVEL <= (SELECT LENGTH (REPLACE (tml, ',', NULL))
FROM xhl_email_list_rec)) LIST
WHERE LIST.tml IS NOT NULL;
BEGIN
l_mail_conn := UTL_SMTP.open_connection (p_host_name);
UTL_SMTP.helo (l_mail_conn, p_host_name);
UTL_SMTP.mail (l_mail_conn, p_from_mail);
FOR email_rec IN email_cur
LOOP
UTL_SMTP.rcpt (l_mail_conn, email_rec.emails);
END LOOP;
UTL_SMTP.open_data (l_mail_conn);
UTL_SMTP.write_data (l_mail_conn, 'From: ' || p_from_mail || UTL_TCP.crlf);
UTL_SMTP.write_data (l_mail_conn, 'Subject: ' || p_subject || UTL_TCP.crlf);
UTL_SMTP.write_data (l_mail_conn, 'To: ' || p_to_mail || UTL_TCP.crlf);
UTL_SMTP.write_data (l_mail_conn, p_message);
UTL_SMTP.close_data (l_mail_conn);
UTL_SMTP.quit (l_mail_conn);
DBMS_OUTPUT.put_line ('Mail sent successfully');
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ( 'Exception in send_mail'
|| SUBSTR (SQLERRM, 1, 200)
);
END common_text_email_prc;
No comments:
Post a Comment