O que esta faltando para que o anexo seja atachado como arquivo?
create or replace procedure PRC_HTML_EMAIL_COM_ANEXO(p_to in varchar2,
p_from in varchar2,
p_subject in varchar2,
p_text in varchar2 default null,
p_html in clob,
p_anexo in clob,
p_nmanexo in varchar2,
p_tamanhoarq in PLS_INTEGER,
p_smtp_hostname in varchar2,
p_smtp_portnum in varchar2) is
l_STEP PLS_INTEGER := 831; --24573;
l_ate PLS_INTEGER;
-- l_tamanhoarq PLS_INTEGER;
l_boundary varchar2(255) default 'a1b2c3d4e3f2g1';
v_conexion_tcp utl_tcp.connection;
l_connection utl_smtp.connection;
l_body_html clob := empty_clob; --This LOB will be the email message
l_offset number;
l_ammount number;
l_temp varchar2(32767) default null;
crlf VARCHAR2(2) := chr(13) || chr(10);
begin
v_conexion_tcp := utl_tcp.open_connection(remote_host => p_smtp_hostname,
remote_port => p_smtp_portnum,
charset => 'AL32UTF8');
l_connection.host := v_conexion_tcp.remote_host;
l_connection.port := v_conexion_tcp.remote_port;
l_connection.tx_timeout := v_conexion_tcp.tx_timeout;
l_connection.private_state := NULL;
l_connection.private_tcp_con := v_conexion_tcp; -- conexão tem que ser desta forma, do contrário o texto não é acentuado
-- l_connection := utl_smtp.open_connection( p_smtp_hostname, p_smtp_portnum );
utl_smtp.helo( l_connection, p_smtp_hostname );
utl_smtp.mail( l_connection, p_from );
utl_smtp.rcpt( l_connection, p_to );
l_temp := l_temp || 'MIME-Version: 1.0' || chr(13) || chr(10);
l_temp := l_temp || 'To: ' || p_to || chr(13) || chr(10);
l_temp := l_temp || 'From: ' || p_from || chr(13) || chr(10);
l_temp := l_temp || 'Subject: ' || p_subject || chr(13) || chr(10);
l_temp := l_temp || 'Reply-To: ' || p_from || chr(13) || chr(10);
l_temp := l_temp || 'Content-Type: multipart/mixed; boundary=' ||
chr(34) || l_boundary || chr(34) || chr(13) ||
chr(10);
----------------------------------------------------
-- Write the headers
dbms_lob.createtemporary( l_body_html, false, 10 );
dbms_lob.write(l_body_html,length(l_temp),1,l_temp);
----------------------------------------------------
-- Write the text boundary
l_offset := dbms_lob.getlength(l_body_html) + 1;
l_temp := '--' || l_boundary || chr(13)||chr(10);
l_temp := l_temp || 'content-type: text/plain; charset=us-ascii' ||
chr(13) || chr(10) || chr(13) || chr(10);
dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);
----------------------------------------------------
-- Write the plain text portion of the email
l_offset := dbms_lob.getlength(l_body_html) + 1;
dbms_lob.write(l_body_html,length(p_text),l_offset,p_text);
----------------------------------------------------
-- Write the HTML boundary
l_temp := chr(13)||chr(10)||chr(13)||chr(10)||'--' || l_boundary ||
chr(13) || chr(10);
l_temp := l_temp || 'content-type: text/html;' ||
chr(13) || chr(10) || chr(13) || chr(10);
l_offset := dbms_lob.getlength(l_body_html) + 1;
dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);
----------------------------------------------------
-- Write the HTML portion of the message
l_offset := dbms_lob.getlength(l_body_html) + 1;
-- dbms_lob.write(l_body_html,length(p_html),l_offset,p_html);
dbms_lob.copy(l_body_html, p_html,dbms_lob.getlength(p_html), l_offset, 1);
----------------------------------------------------
-- Write the final html boundary
l_temp := chr(13) || chr(10) || '--' || l_boundary || '--' || chr(13);
l_offset := dbms_lob.getlength(l_body_html) + 1;
dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);
----------------------------------------------------
-- Send the email in 1900 byte chunks to UTL_SMTP
l_offset := 1;
l_ammount := 1900;
utl_smtp.open_data(l_connection);
while l_offset < dbms_lob.getlength(l_body_html) loop
utl_smtp.write_data(l_connection,
dbms_lob.substr(l_body_html,l_ammount,l_offset));
l_offset := l_offset + l_ammount ;
l_ammount := least(1900,dbms_lob.getlength(l_body_html) - l_ammount);
end loop;
-- Attach Info
utl_smtp.write_raw_data(l_connection, utl_raw.cast_to_raw('--SECBOUND' || crlf));
utl_smtp.write_raw_data(l_connection, utl_raw.cast_to_raw('Content-Type: text/plain ' ||
' name="'|| p_nmanexo || '"' || crlf));
utl_smtp.write_raw_data(l_connection, utl_raw.cast_to_raw('Content-Disposition: attachment; filename="'
|| p_nmanexo || '"' || crlf || crlf));
-- Attach body
l_offset := 1;
l_ammount := 1900;
WHILE l_offset < p_tamanhoarq LOOP
utl_smtp.write_raw_data(l_connection, utl_raw.cast_to_raw(dbms_lob.substr(p_anexo, l_ammount, l_offset)));
l_offset := l_offset + l_ammount;
END LOOP;
utl_smtp.write_raw_data(l_connection, utl_raw.cast_to_raw('' || crlf));
-- Last boundry
utl_smtp.write_raw_data(l_connection, utl_raw.cast_to_raw('--SECBOUND--' || crlf));
utl_smtp.close_data(l_connection);
-- utl_smtp.quit(l_connection);
utl_tcp.close_connection(v_conexion_tcp);
dbms_lob.freetemporary(l_body_html);
end PRC_HTML_EMAIL_COM_ANEXO;