Multiple Attachment problems in PL/SQL using utl_smtp package
I'm using the code from this link to send attachments in the email notifications of our system;
http://www.builderau.com.au/program/oracle/soa/Sending-blob-attachments-in-e-mail-with-utl-smtp/0,339028441,339284536,00.htm
The problem is that the second attachment has encoding issue. So if i send in a text file, the text in the txt file will be all mashed up.. Like the first 23 characters are printed correctly then there is a mash of text like 'B•Ú]\ÈØ]\‹[ÝH' then it continues with the text 开发者_StackOverflowand same thing happens after 23 characters again...
For the first attachment, I print the MIME boundary;
utl_smtp.write_data(g_mail_conn, chr(13)||chr(10)||chr(13)||chr(10)||'--' || l_boundary ||
chr(13) || chr(10));
utl_smtp.write_data( g_mail_conn, 'Content-Disposition: attachment; filename="test2.txt"' || chr(13) || chr(10));
utl_smtp.write_data( g_mail_conn, 'Content-Transfer-Encoding: base64' || chr(13) || chr(10) );
Then I run the while loop that i took from the link (copied below as well) and then after the loop, I reset the v_offset variable, then i put the same code above for the second boundary for the attachment.. Then i close the MIME boundaries at the end with
utl_smtp.write_data(g_mail_conn,chr(13) || chr(10) || '--' || l_boundary || '--' || chr(13));
Any ideas why this problem is happening?
The While loop;
<<while_loop>>
while v_offset < v_length loop
dbms_lob.read( p_blob, v_buffer_size, v_offset, v_raw );
utl_smtp.write_raw_data( c, utl_encode.base64_encode(v_raw) );
utl_smtp.write_data( c, utl_tcp.crlf );
v_offset := v_offset + v_buffer_size;
end loop while_loop;
I just found the solution...
The v_buffer_size variable was getting modified in the dbms_lob.read() procedure, so before attaching the new file, I just had to reset it back to 57 along with setting v_offset to 1..
精彩评论