{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}} \viewkind4\uc1\pard\f0\fs20 CREATE OR REPLACE PROCEDURE "SEND_HTML_MAIL"("MAIL_TO" IN VARCHAR2, "MAIL_FROM" IN VARCHAR2, "MAIL_SUBJECT" IN VARCHAR2, "MAIL_TEXT" IN VARCHAR2 DEFAULT NULL, "MAIL_HTML" IN VARCHAR2 DEFAULT NULL, "SMTP_HOSTNAME" IN VARCHAR2, "SMTP_PORT" IN VARCHAR2) IS \par l_boundary varchar2(255) default 'a1b2c3d4e3f2g1';\par l_connection utl_smtp.connection;\par l_body_html clob := empty_clob; --This LOB will be the email message\par l_offset number;\par l_ammount number;\par l_temp varchar2(32767) default null;\par begin\par l_connection := utl_smtp.open_connection( smtp_hostname, smtp_port );\par utl_smtp.helo( l_connection, smtp_hostname );\par utl_smtp.mail( l_connection, mail_from );\par utl_smtp.rcpt( l_connection, mail_to );\par \par l_temp := l_temp || 'MIME-Version: 1.0' || chr(13) || chr(10);\par l_temp := l_temp || 'To: ' || mail_to || chr(13) || chr(10);\par l_temp := l_temp || 'From: ' || mail_from || chr(13) || chr(10);\par l_temp := l_temp || 'Subject: ' || mail_subject || chr(13) || chr(10);\par l_temp := l_temp || 'Reply-To: ' || mail_from || chr(13) || chr(10);\par l_temp := l_temp || 'Content-Type: multipart/alternative; boundary=' || \par chr(34) || l_boundary || chr(34) || chr(13) || \par chr(10);\par \par ----------------------------------------------------\par -- Write the headers\par dbms_lob.createtemporary( l_body_html, false, 10 );\par dbms_lob.write(l_body_html,length(l_temp),1,l_temp);\par \par \par ----------------------------------------------------\par -- Write the text boundary\par l_offset := dbms_lob.getlength(l_body_html) + 1;\par l_temp := '--' || l_boundary || chr(13)||chr(10);\par l_temp := l_temp || 'content-type: text/plain; charset=us-ascii' || \par chr(13) || chr(10) || chr(13) || chr(10);\par dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);\par \par ----------------------------------------------------\par -- Write the plain text portion of the email\par l_offset := dbms_lob.getlength(l_body_html) + 1;\par dbms_lob.write(l_body_html,length(mail_text),l_offset,mail_text);\par \par ----------------------------------------------------\par -- Write the HTML boundary\par l_temp := chr(13)||chr(10)||chr(13)||chr(10)||'--' || l_boundary || \par chr(13) || chr(10);\par l_temp := l_temp || 'content-type: text/html;' || \par chr(13) || chr(10) || chr(13) || chr(10);\par l_offset := dbms_lob.getlength(l_body_html) + 1;\par dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);\par \par ----------------------------------------------------\par -- Write the HTML portion of the message\par l_offset := dbms_lob.getlength(l_body_html) + 1;\par dbms_lob.write(l_body_html,length(mail_html),l_offset,mail_html);\par \par ----------------------------------------------------\par -- Write the final html boundary\par l_temp := chr(13) || chr(10) || '--' || l_boundary || '--' || chr(13);\par l_offset := dbms_lob.getlength(l_body_html) + 1;\par dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);\par \par \par ----------------------------------------------------\par -- Send the email in 1900 byte chunks to UTL_SMTP\par l_offset := 1;\par l_ammount := 1900;\par utl_smtp.open_data(l_connection);\par while l_offset < dbms_lob.getlength(l_body_html) loop\par utl_smtp.write_data(l_connection,\par dbms_lob.substr(l_body_html,l_ammount,l_offset));\par l_offset := l_offset + l_ammount ;\par l_ammount := least(1900,dbms_lob.getlength(l_body_html) - l_ammount);\par end loop;\par utl_smtp.close_data(l_connection);\par utl_smtp.quit( l_connection );\par dbms_lob.freetemporary(l_body_html);\par end;\par /\par \par }