title: Multiple Attachment problems in PL/SQL using utl_smtp package
body: <p>I'm using the code from this link to send attachments in the email notifications of our system;</p>
  
  <p><a href="http://www.builderau.com.au/program/oracle/soa/Sending-blob-attachments-in-e-mail-with-utl-smtp/0,339028441,339284536,00.htm" rel="nofollow noreferrer">http://www.builderau.com.au/program/oracle/soa/Sending-blob-attachments-in-e-mail-with-utl-smtp/0,339028441,339284536,00.htm</a></p>
  
  <p>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 and same thing happens after 23 characters again...</p>
  
  <p>For the first attachment, I print the MIME boundary;</p>
  
  <pre><code>    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) );
  </code></pre>
  
  <p>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</p>
  
  <pre><code>utl_smtp.write_data(g_mail_conn,chr(13) || chr(10) || '--' ||  l_boundary || '--' || chr(13)); 
  </code></pre>
  
  <p>Any ideas why this problem is happening?</p>
  
  <p>The While loop;</p>
  
  <pre><code>&lt;&lt;while_loop&gt;&gt;
  while v_offset &lt; 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;
  </code></pre>