Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

procedure KMBL_ALERT(v_clob CLOB, v_Subject nvarchar2) is

v_connection UTL_SMTP.connection;
-- mime blocks (the sections of the email body that can become attachments)
-- must be delimited by a string, this particular string is just an example
c_mime_boundary CONSTANT VARCHAR2(256) := '-----AABCDEFBBCCC0123456789DE';
--v_clob CLOB := EMPTY_CLOB();
v_len INTEGER;
v_index INTEGER;
v_email varchar2(10000);
v_Cc varchar2(10000);
v_text varchar2(10000) := 'Dear Sir,

List of transactions which goes in error are attached.


Please have a look.

Regards,
Interface Program
';
l_message VARCHAR2(32767) := '<html>
<body>
<br>
Test HTML with Embedded Image-chk latest
<p>And here it is:</p>
<p>The end.</p>
</body>
</html>
';
BEGIN
-- Build the contents before connecting to the mail server
-- that way you can begin pumping the data immediately
-- and not risk an SMTP timeout

v_email := 'Niaz.Ahmad@kb.com.pk,
Afzal.Amin@kb.com.pk,
Irfan.Khan@kb.com.pk,
Muhammad.Umar@kb.com.pk';

v_Cc := 'pwc.consultant1@Kb.com.pk';

/*v_clob := v_clob || 'TRAN_TYPE' || ' , ' || 'TRANSACTION_ID' || ' , ' ||


'PAYMENT_ID' || ' , ' || 'FT_NUMBER' || ' , ' || 'PAY_ORDER' ||
' , ' || 'PAYMENT_METHOD' || ' , ' || 'AMOUNT' || ' , ' ||
'TRANSACTION_STATUS' || ' , ' || 'CLEARANCE_STATUS' || ' , ' ||
'CANCELATION_STATUS' || ' , ' || UTL_TCP.crlf;*/

/*FOR x IN (select * from KMBL_IN_REP) LOOP


v_clob := v_clob || x.tran_type || ' , ' || x.transaction_id || ' , ' ||
x.payment_id || ' , ' || x.ft_number || ' , ' ||
x.pay_order || ' , ' || x.payment_method || ' , ' ||
x.amount || ' , ' || x.transaction_status || ' , ' ||
x.clearance_status || ' , ' || x.cancelation_status ||
' , ' || UTL_TCP.crlf;
END LOOP;*/

v_connection := UTL_SMTP.open_connection('10.10.1.81');
UTL_SMTP.helo(v_connection, '10.10.1.81');
UTL_SMTP.mail(v_connection, 'Infotech.HRMS@Kb.com.pk');
UTL_SMTP.rcpt(v_connection, 'pwc.consultant1@Kb.com.pk');

UTL_SMTP.rcpt(v_connection, 'Niaz.Ahmad@kb.com.pk');
UTL_SMTP.rcpt(v_connection, 'Afzal.Amin@kb.com.pk');
UTL_SMTP.rcpt(v_connection, 'Irfan.Khan@kb.com.pk');
UTL_SMTP.rcpt(v_connection, 'Muhammad.Umar@kb.com.pk');

UTL_SMTP.open_data(v_connection);

UTL_SMTP.write_data(v_connection,
'From: ' || 'Infotech.HRMS@Kb.com.pk' ||
UTL_TCP.crlf);
UTL_SMTP.write_data(v_connection,
'To: ' || v_email --'pwc.lhr@bankalfalah.com'
|| UTL_TCP.crlf);
UTL_SMTP.write_data(v_connection, 'CC: ' || v_Cc || UTL_TCP.crlf);
UTL_SMTP.write_data(v_connection,
'Subject: ' || v_Subject || UTL_TCP.crlf);
-- UTL_SMTP.write_data(v_connection, 'Body: some text.....'|| UTL_TCP.crlf);
-- UTL_SMTP.write_data(v_connection, 'Some Message Text.....' || UTL_TCP.crlf
|| UTL_TCP.crlf);
UTL_SMTP.write_data(v_connection, 'MIME-Version: 1.0' || UTL_TCP.crlf);

UTL_SMTP.write_data(v_connection,
'Content-Type: multipart/mixed; boundary="' ||
c_mime_boundary || '"' || UTL_TCP.crlf);
UTL_SMTP.write_data(v_connection, UTL_TCP.crlf);
UTL_SMTP.write_data(v_connection,
'This is a multi-part message in MIME format.' ||
UTL_TCP.crlf);

-- UTL_SMTP.write_data(v_connection, UTL_TCP.CRLF);
-- UTL_SMTP.write_data(v_connection, l_message);
-- UTL_SMTP.write_data(v_connection, UTL_TCP.CRLF);
UTL_SMTP.write_data(v_connection,
'--' || c_mime_boundary || UTL_TCP.crlf);
UTL_SMTP.write_data(v_connection,
'Content-Type: text/plain charset="iso-8859-1"' ||
UTL_TCP.crlf || UTL_TCP.crlf);
UTL_SMTP.write_data(v_connection, v_text);
UTL_SMTP.write_data(v_connection, UTL_TCP.crlf || UTL_TCP.crlf);

-- Set up attachment header


UTL_SMTP.write_data(v_connection,
'--' || c_mime_boundary || UTL_TCP.crlf);
UTL_SMTP.write_data(v_connection,
'Content-Disposition: attachment; filename="' ||
'Transactions.csv' || '"' || UTL_TCP.crlf);
UTL_SMTP.write_data(v_connection, UTL_TCP.crlf);

-- Write attachment contents

v_len := DBMS_LOB.getlength(v_clob);
v_index := 1;

WHILE v_index <= v_len LOOP


-- UTL_SMTP.data(v_connection,'Some Message Text....');
UTL_SMTP.write_data(v_connection,
DBMS_LOB.SUBSTR(v_clob, 32000, v_index));
v_index := v_index + 32000;
END LOOP;

--
-- End attachment
UTL_SMTP.write_data(v_connection, UTL_TCP.crlf);
UTL_SMTP.write_data(v_connection,
'--' || c_mime_boundary || '--' || UTL_TCP.crlf);

UTL_SMTP.close_data(v_connection);
UTL_SMTP.quit(v_connection);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.put_line('Alert Pro Error');
-- DBMS_OUTPUT.put_line( 'Alert Pro Error' ||
DBMS_UTILITY.format_error_stack);

END;

You might also like