Forum Stats

  • 3,839,819 Users
  • 2,262,538 Discussions
  • 7,901,063 Comments

Discussions

How do I use Oracle's UTL_SMTP to send a message body that included an embedded image

PhilMan2
PhilMan2 Member Posts: 380 Bronze Badge
edited Dec 27, 2014 1:39AM in SQL & PL/SQL

I'm attempting to use Oracle's 11.g's UTL_SMTP to send a message body that includes an embedded image. I have this process working for a standard text body, and for an eMail that may contain attachments (Word doc, JPG image, etc.). I'm stuck on making this work with an image embedded in the body of the eMail. When I include and embedded image, the eMail displays in Outlook 2013 as a red X where the image should be. The rest of the text appears fine. The html body of the eMail is passed in to the procedure via "p_html".

My Procedure looks like this:

<span class="kwd">create</span><span class="pln"> </span><span class="kwd">or</span><span class="pln"> replace </span><span class="kwd">procedure</span><span class="pln"> html_email_attachments</span><span class="pun">(</span><span class="pln"><br/>  p_to  </span><span class="kwd">in</span><span class="pln"> varchar2</span><span class="pun">,</span><span class="pln"><br/>  p_from  </span><span class="kwd">in</span><span class="pln"> varchar2</span><span class="pun">,</span><span class="pln"><br/>  p_subject  </span><span class="kwd">in</span><span class="pln"> varchar2</span><span class="pun">,</span><span class="pln"><br/>  p_text  </span><span class="kwd">in</span><span class="pln"> varchar2 </span><span class="kwd">default</span><span class="pln"> </span><span class="kwd">null</span><span class="pun">,</span><span class="pln"><br/>  p_html  </span><span class="kwd">in</span><span class="pln"> varchar2 </span><span class="kwd">default</span><span class="pln"> </span><span class="kwd">null</span><span class="pun">,</span><span class="pln"><br/>  p_smtp_hostname  </span><span class="kwd">in</span><span class="pln"> varchar2</span><span class="pun">,</span><span class="pln"><br/>  p_smtp_portnum  </span><span class="kwd">in</span><span class="pln"> varchar2</span><span class="pun">,</span><span class="pln"><br/>  p_smtp_username  </span><span class="kwd">in</span><span class="pln"> varchar2</span><span class="pun">,</span><span class="pln"><br/>  p_smtp_password  </span><span class="kwd">in</span><span class="pln"> varchar2</span><span class="pun">,</span><span class="pln"><br/>  p_event_pkey  </span><span class="kwd">in</span><span class="pln"> number<br/>   </span><span class="pun">)</span><span class="pln"><br/></span><span class="kwd">is</span><span class="pln"><br/>  l_boundary varchar2</span><span class="pun">(</span><span class="lit">255</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">default</span><span class="pln"> </span><span class="str">'a1b2c3d4e3f2g1'</span><span class="pun">;</span><span class="pln"><br/>  l_connection utl_smtp</span><span class="pun">.</span><span class="pln">connection</span><span class="pun">;</span><span class="pln"><br/>  l_body_html clob </span><span class="pun">:=</span><span class="pln"> empty_clob</span><span class="pun">;</span><span class="pln"> </span><span class="com">--This LOB will be the email message</span><span class="pln"><br/>  l_offset number</span><span class="pun">;</span><span class="pln"><br/>  l_ammount number</span><span class="pun">;</span><span class="pln"><br/>  l_temp varchar2</span><span class="pun">(</span><span class="lit">32767</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">default</span><span class="pln"> </span><span class="kwd">null</span><span class="pun">;</span><span class="pln"><br/>  l_encoded_username varchar2</span><span class="pun">(</span><span class="lit">2048</span><span class="pun">);</span><span class="pln"><br/>  l_encoded_password varchar2</span><span class="pun">(</span><span class="lit">2048</span><span class="pun">);</span><span class="pln"><br/>  l_attach_mime varchar2</span><span class="pun">(</span><span class="lit">1024</span><span class="pun">);</span><span class="pln"><br/>  l_attach_name varchar2</span><span class="pun">(</span><span class="lit">1024</span><span class="pun">);</span><span class="pln"><br/>  l_attach_blob blob</span><span class="pun">;</span><span class="pln"><br/>  l_attachment_pkeys DBMS_SQL</span><span class="pun">.</span><span class="pln">varchar2_table</span><span class="pun">;</span><span class="pln"><br/>  l_step PLS_INTEGER  </span><span class="pun">:=</span><span class="pln"> </span><span class="lit">12000</span><span class="pun">;</span><span class="pln"> </span><span class="com">-- A multiple of 3 and <= 24573</span><span class="pln"><br/>  crlf varchar2</span><span class="pun">(</span><span class="lit">2</span><span class="pun">)</span><span class="pln"> </span><span class="pun">:=</span><span class="pln"> CHR</span><span class="pun">(</span><span class="lit">13</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> CHR</span><span class="pun">(</span><span class="lit">10</span><span class="pun">);</span><span class="pln"><br/>  diag varchar2</span><span class="pun">(</span><span class="lit">4000</span><span class="pun">);</span><span class="pln"><br/>  v_raw raw</span><span class="pun">(</span><span class="lit">57</span><span class="pun">);</span><span class="pln"><br/>  v_length integer </span><span class="pun">:=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln"><br/>  v_buffer_size integer </span><span class="pun">:=</span><span class="pln"> </span><span class="lit">57</span><span class="pun">;</span><span class="pln"><br/>  v_offset integer </span><span class="pun">:=</span><span class="pln"> </span><span class="lit">1</span><span class="pun">;</span><span class="pln"><br/></span><span class="kwd">begin</span><span class="pln"><br/></span><span class="com">-- Store all the attachment primary keys into l_attachment_pkeys  </span><span class="pln"><br/>   </span><span class="kwd">Select</span><span class="pln"> ma</span><span class="pun">.</span><span class="pln">prim_key  </span><span class="kwd">Bulk</span><span class="pln"> Collect </span><span class="kwd">Into</span><span class="pln"> l_attachment_pkeys<br/>   </span><span class="kwd">From</span><span class="pln">  mail_attachment ma<br/>   </span><span class="kwd">Where</span><span class="pln"> ma</span><span class="pun">.</span><span class="pln">event_fkey </span><span class="pun">=</span><span class="pln"> p_event_pkey</span><span class="pun">;</span><span class="pln"><br/></span><span class="com">-- Encode p_smtp_username and p_smtp_password</span><span class="pln"><br/>  l_encoded_username </span><span class="pun">:=</span><span class="pln"> UTL_RAW</span><span class="pun">.</span><span class="pln">cast_to_varchar2<br/>   </span><span class="pun">(</span><span class="pln">UTL_ENCODE</span><span class="pun">.</span><span class="pln">base64_encode</span><span class="pun">(</span><span class="pln">UTL_RAW</span><span class="pun">.</span><span class="pln">cast_to_raw</span><span class="pun">(</span><span class="pln">p_smtp_username</span><span class="pun">)));</span><span class="pln"> <br/>  l_encoded_password </span><span class="pun">:=</span><span class="pln"> UTL_RAW</span><span class="pun">.</span><span class="pln">cast_to_varchar2<br/>   </span><span class="pun">(</span><span class="pln">UTL_ENCODE</span><span class="pun">.</span><span class="pln">base64_encode</span><span class="pun">(</span><span class="pln">UTL_RAW</span><span class="pun">.</span><span class="pln">cast_to_raw</span><span class="pun">(</span><span class="pln">p_smtp_password</span><span class="pun">)));</span><span class="pln"> <br/></span><span class="com">-- set the l_connection variable</span><span class="pln"><br/>  l_connection </span><span class="pun">:=</span><span class="pln"> UTL_SMTP</span><span class="pun">.</span><span class="pln">open_connection</span><span class="pun">(</span><span class="pln">p_smtp_hostname</span><span class="pun">,</span><span class="pln"> p_smtp_portnum</span><span class="pun">);</span><span class="pln"> <br/></span><span class="com">-- begin the connection</span><span class="pln"><br/>  utl_smtp</span><span class="pun">.</span><span class="pln">ehlo</span><span class="pun">(</span><span class="pln">l_connection</span><span class="pun">,</span><span class="pln"> p_smtp_hostname</span><span class="pun">);</span><span class="com">--DO NOT USE HELO </span><span class="pln"><br/></span><span class="com">-- authenticate to the server using the encoded username and password</span><span class="pln"><br/>  utl_smtp</span><span class="pun">.</span><span class="pln">command</span><span class="pun">(</span><span class="pln">l_connection</span><span class="pun">,</span><span class="pln"> </span><span class="str">'AUTH'</span><span class="pun">,</span><span class="pln"> </span><span class="str">'LOGIN'</span><span class="pun">);</span><span class="pln"> <br/>  utl_smtp</span><span class="pun">.</span><span class="pln">command</span><span class="pun">(</span><span class="pln">l_connection</span><span class="pun">,</span><span class="pln"> l_encoded_username</span><span class="pun">);</span><span class="pln"> <br/>  utl_smtp</span><span class="pun">.</span><span class="pln">command</span><span class="pun">(</span><span class="pln">l_connection</span><span class="pun">,</span><span class="pln"> l_encoded_password</span><span class="pun">);</span><span class="pln"><br/></span><span class="com">-- First, establish the mail's From and To. This is essential</span><span class="pln"><br/>  utl_smtp</span><span class="pun">.</span><span class="pln">mail</span><span class="pun">(</span><span class="pln"> l_connection</span><span class="pun">,</span><span class="pln"> p_from </span><span class="pun">);</span><span class="pln"><br/>  utl_smtp</span><span class="pun">.</span><span class="pln">rcpt</span><span class="pun">(</span><span class="pln"> l_connection</span><span class="pun">,</span><span class="pln"> p_to </span><span class="pun">);</span><span class="pln"><br/></span><span class="com">-- Define the Header </span><span class="pln"><br/>  l_temp </span><span class="pun">:=</span><span class="pln"> l_temp </span><span class="pun">||</span><span class="pln"> </span><span class="str">'MIME-Version: 1.0'</span><span class="pln">   </span><span class="pun">||</span><span class="pln"> crlf</span><span class="pun">;</span><span class="pln"><br/>  l_temp </span><span class="pun">:=</span><span class="pln"> l_temp </span><span class="pun">||</span><span class="pln"> </span><span class="str">'To: '</span><span class="pln">   </span><span class="pun">||</span><span class="pln"> p_to  </span><span class="pun">||</span><span class="pln"> crlf</span><span class="pun">;</span><span class="pln"><br/>  l_temp </span><span class="pun">:=</span><span class="pln"> l_temp </span><span class="pun">||</span><span class="pln"> </span><span class="str">'From: '</span><span class="pln">   </span><span class="pun">||</span><span class="pln"> p_from  </span><span class="pun">||</span><span class="pln"> crlf</span><span class="pun">;</span><span class="pln"><br/>  l_temp </span><span class="pun">:=</span><span class="pln"> l_temp </span><span class="pun">||</span><span class="pln"> </span><span class="str">'Subject: '</span><span class="pln">  </span><span class="pun">||</span><span class="pln"> p_subject  </span><span class="pun">||</span><span class="pln"> crlf</span><span class="pun">;</span><span class="pln"><br/>  l_temp </span><span class="pun">:=</span><span class="pln"> l_temp </span><span class="pun">||</span><span class="pln"> </span><span class="str">'Reply-To: '</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> p_from  </span><span class="pun">||</span><span class="pln"> crlf</span><span class="pun">;</span><span class="pln"><br/>  l_temp </span><span class="pun">:=</span><span class="pln"> l_temp </span><span class="pun">||</span><span class="pln"> </span><span class="str">'Content-Type: multipart/mixed; boundary='</span><span class="pln"> </span><span class="pun">||</span><span class="pln"><br/>  chr</span><span class="pun">(</span><span class="lit">34</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> l_boundary </span><span class="pun">||</span><span class="pln">  chr</span><span class="pun">(</span><span class="lit">34</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> crlf</span><span class="pun">;</span><span class="pln"><br/><br/>   </span><span class="com">----------------------------------------------------</span><span class="pln"><br/>   </span><span class="com">-- Write the headers</span><span class="pln"><br/>  dbms_lob</span><span class="pun">.</span><span class="pln">createtemporary</span><span class="pun">(</span><span class="pln"> l_body_html</span><span class="pun">,</span><span class="pln"> false</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pln"> </span><span class="pun">);</span><span class="pln"><br/>  dbms_lob</span><span class="pun">.</span><span class="pln">write</span><span class="pun">(</span><span class="pln">l_body_html</span><span class="pun">,</span><span class="pln">length</span><span class="pun">(</span><span class="pln">l_temp</span><span class="pun">),</span><span class="lit">1</span><span class="pun">,</span><span class="pln">l_temp</span><span class="pun">);</span><span class="pln"><br/><br/>   </span><span class="com">----------------------------------------------------</span><span class="pln"><br/>   </span><span class="com">-- Write the HTML boundary</span><span class="pln"><br/>   </span><span class="com">-- Identify the content type as text/html</span><span class="pln"><br/>   </span><span class="com">-- Determine the offset (initially it's 1)</span><span class="pln"><br/>   </span><span class="com">-- Write out </span><span class="pln"><br/>  l_temp  </span><span class="pun">:=</span><span class="pln"> crlf </span><span class="pun">||</span><span class="pln"> crlf </span><span class="pun">||</span><span class="str">'--'</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> l_boundary </span><span class="pun">||</span><span class="pln"> crlf</span><span class="pun">;</span><span class="pln"><br/>  l_temp  </span><span class="pun">:=</span><span class="pln"> l_temp </span><span class="pun">||</span><span class="pln"> </span><span class="str">'content-type: text/html;'</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> crlf </span><span class="pun">||</span><span class="pln"> crlf</span><span class="pun">;</span><span class="pln"><br/>  l_offset </span><span class="pun">:=</span><span class="pln"> dbms_lob</span><span class="pun">.</span><span class="pln">getlength</span><span class="pun">(</span><span class="pln">l_body_html</span><span class="pun">)</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> </span><span class="lit">1</span><span class="pun">;</span><span class="pln"><br/>  dbms_lob</span><span class="pun">.</span><span class="pln">write</span><span class="pun">(</span><span class="pln">l_body_html</span><span class="pun">,</span><span class="pln">length</span><span class="pun">(</span><span class="pln">l_temp</span><span class="pun">),</span><span class="pln">l_offset</span><span class="pun">,</span><span class="pln">l_temp</span><span class="pun">);</span><span class="pln"><br/><br/>   </span><span class="com">----------------------------------------------------</span><span class="pln"><br/>   </span><span class="com">-- Write the HTML portion of the message</span><span class="pln"><br/>  l_offset </span><span class="pun">:=</span><span class="pln"> dbms_lob</span><span class="pun">.</span><span class="pln">getlength</span><span class="pun">(</span><span class="pln">l_body_html</span><span class="pun">)</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> </span><span class="lit">1</span><span class="pun">;</span><span class="pln"><br/>  dbms_lob</span><span class="pun">.</span><span class="pln">write</span><span class="pun">(</span><span class="pln">l_body_html</span><span class="pun">,</span><span class="pln">length</span><span class="pun">(</span><span class="pln">p_html</span><span class="pun">),</span><span class="pln">l_offset</span><span class="pun">,</span><span class="pln">p_html</span><span class="pun">);</span><span class="pln"><br/>   </span><span class="com">----------------------------------------------------</span><span class="pln"><br/>   </span><span class="com">-- Send the email body in 1900 byte chunks to UTL_SMTP</span><span class="pln"><br/>  l_offset  </span><span class="pun">:=</span><span class="pln"> </span><span class="lit">1</span><span class="pun">;</span><span class="pln"><br/>  l_ammount </span><span class="pun">:=</span><span class="pln"> </span><span class="lit">1900</span><span class="pun">;</span><span class="pln"><br/>  utl_smtp</span><span class="pun">.</span><span class="pln">open_data</span><span class="pun">(</span><span class="pln">l_connection</span><span class="pun">);</span><span class="pln"><br/><br/>   </span><span class="kwd">while</span><span class="pln"> l_offset </span><span class="pun"><</span><span class="pln"> dbms_lob</span><span class="pun">.</span><span class="pln">getlength</span><span class="pun">(</span><span class="pln">l_body_html</span><span class="pun">)</span><span class="pln"> loop<br/>  utl_smtp</span><span class="pun">.</span><span class="pln">write_data</span><span class="pun">(</span><span class="pln">l_connection</span><span class="pun">,</span><span class="pln"><br/>  dbms_lob</span><span class="pun">.</span><span class="pln">substr</span><span class="pun">(</span><span class="pln">l_body_html</span><span class="pun">,</span><span class="pln">l_ammount</span><span class="pun">,</span><span class="pln">l_offset</span><span class="pun">));</span><span class="pln"><br/>  l_offset  </span><span class="pun">:=</span><span class="pln"> l_offset </span><span class="pun">+</span><span class="pln"> l_ammount </span><span class="pun">;</span><span class="pln"><br/>  l_ammount </span><span class="pun">:=</span><span class="pln"> least</span><span class="pun">(</span><span class="lit">1900</span><span class="pun">,</span><span class="pln">dbms_lob</span><span class="pun">.</span><span class="pln">getlength</span><span class="pun">(</span><span class="pln">l_body_html</span><span class="pun">)</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> l_ammount</span><span class="pun">);</span><span class="pln"><br/>   </span><span class="kwd">end</span><span class="pln"> loop</span><span class="pun">;</span><span class="pln"><br/>   </span><span class="com">--The following crlf is necessary after the body is written</span><span class="pln"><br/>  utl_smtp</span><span class="pun">.</span><span class="pln">write_data</span><span class="pun">(</span><span class="pln">l_connection</span><span class="pun">,</span><span class="pln"> crlf</span><span class="pun">);</span><span class="pln"><br/>   </span><span class="com">----------------------------------------------------</span><span class="pln"><br/>   </span><span class="com">-- Write the attachments of the message</span><span class="pln"><br/>   </span><span class="com">-- Loop through all the selected primary keys in l_attachment_pkeys</span><span class="pln"><br/>   </span><span class="kwd">While</span><span class="pln"> l_attachment_pkeys </span><span class="kwd">is</span><span class="pln"> </span><span class="kwd">null</span><span class="pln"><br/>  Loop<br/>   </span><span class="kwd">For</span><span class="pln"> i </span><span class="kwd">IN</span><span class="pln"> l_attachment_pkeys</span><span class="pun">.</span><span class="pln">FIRST </span><span class="pun">..</span><span class="pln"> l_attachment_pkeys</span><span class="pun">.</span><span class="pln">LAST<br/>  Loop<br/>   </span><span class="com">-- Determine the attachment variables for each instance of attachments</span><span class="pln"><br/>   </span><span class="kwd">Select</span><span class="pln"> mime_type  </span><span class="kwd">into</span><span class="pln"> l_attach_mime <br/>   </span><span class="kwd">from</span><span class="pln"> mail_attachment </span><span class="kwd">where</span><span class="pln"> prim_key </span><span class="pun">=</span><span class="pln"> l_attachment_pkeys</span><span class="pun">(</span><span class="pln">i</span><span class="pun">);</span><span class="pln"><br/>   </span><span class="kwd">Select</span><span class="pln"> file_name  </span><span class="kwd">into</span><span class="pln"> l_attach_name <br/>   </span><span class="kwd">from</span><span class="pln"> mail_attachment </span><span class="kwd">where</span><span class="pln"> prim_key </span><span class="pun">=</span><span class="pln"> l_attachment_pkeys</span><span class="pun">(</span><span class="pln">i</span><span class="pun">);</span><span class="pln"><br/>   </span><span class="kwd">Select</span><span class="pln"> attachment </span><span class="kwd">into</span><span class="pln"> l_attach_blob <br/>   </span><span class="kwd">from</span><span class="pln"> mail_attachment </span><span class="kwd">where</span><span class="pln"> prim_key </span><span class="pun">=</span><span class="pln"> l_attachment_pkeys</span><span class="pun">(</span><span class="pln">i</span><span class="pun">);</span><span class="pln"><br/>  v_length </span><span class="pun">:=</span><span class="pln"> dbms_lob</span><span class="pun">.</span><span class="pln">getlength</span><span class="pun">(</span><span class="pln">l_attach_blob</span><span class="pun">);</span><span class="pln"><br/><br/>   </span><span class="com">-- Write out the boundary</span><span class="pln"><br/>  UTL_SMTP</span><span class="pun">.</span><span class="pln">write_data</span><span class="pun">(</span><span class="pln">l_connection</span><span class="pun">,</span><span class="pln"> </span><span class="str">'--'</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> l_boundary </span><span class="pun">||</span><span class="pln"> crlf</span><span class="pun">);</span><span class="pln"><br/>   </span><span class="com">-- Write out the attachment metadata</span><span class="pln"><br/>  UTL_SMTP</span><span class="pun">.</span><span class="pln">write_data</span><span class="pun">(</span><span class="pln">l_connection</span><span class="pun">,</span><span class="pln"> </span><span class="str">'Content-Type: '</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> l_attach_mime </span><span class="pun">||</span><span class="pln"> <br/>   </span><span class="str">'; name='</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> chr</span><span class="pun">(</span><span class="lit">34</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> l_attach_name </span><span class="pun">||</span><span class="pln"> chr</span><span class="pun">(</span><span class="lit">34</span><span class="pun">)</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> crlf</span><span class="pun">);</span><span class="pln"><br/>  UTL_SMTP</span><span class="pun">.</span><span class="pln">write_data</span><span class="pun">(</span><span class="pln">l_connection</span><span class="pun">,</span><span class="pln"> </span><span class="str">'Content-Transfer-Encoding: base64'</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> <br/>  crlf</span><span class="pun">);</span><span class="pln"><br/>  UTL_SMTP</span><span class="pun">.</span><span class="pln">write_data</span><span class="pun">(</span><span class="pln">l_connection</span><span class="pun">,</span><span class="pln"> </span><span class="str">'Content-Disposition: attachment; <br/>  filename="'</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> l_attach_name </span><span class="pun">||</span><span class="pln"> </span><span class="str">'"'</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> crlf </span><span class="pun">||</span><span class="pln"> crlf</span><span class="pun">);</span><span class="pln"><br/>   </span><span class="com">--Write out the attachment blob in portions of l_step length</span><span class="pln"><br/>   </span><span class="kwd">FOR</span><span class="pln"> k </span><span class="kwd">IN</span><span class="pln"> </span><span class="lit">0</span><span class="pln"> </span><span class="pun">..</span><span class="pln"> TRUNC</span><span class="pun">((</span><span class="pln">DBMS_LOB</span><span class="pun">.</span><span class="pln">getlength</span><span class="pun">(</span><span class="pln">l_attach_blob</span><span class="pun">)</span><span class="pln"> </span><span class="pun">-</span><span class="pln"> </span><span class="lit">1</span><span class="pln"> </span><span class="pun">)/</span><span class="pln">l_step</span><span class="pun">)</span><span class="pln"> <br/>  LOOP<br/>  UTL_SMTP</span><span class="pun">.</span><span class="pln">write_data</span><span class="pun">(</span><span class="pln">l_connection</span><span class="pun">,</span><span class="pln"> UTL_RAW</span><span class="pun">.</span><span class="pln">cast_to_varchar2<br/>   </span><span class="pun">(</span><span class="pln">UTL_ENCODE</span><span class="pun">.</span><span class="pln">base64_encode</span><span class="pun">(</span><span class="pln">DBMS_LOB</span><span class="pun">.</span><span class="pln">substr</span><span class="pun">(</span><span class="pln">l_attach_blob</span><span class="pun">,</span><span class="pln"> <br/>  l_step</span><span class="pun">,</span><span class="pln"> k </span><span class="pun">*</span><span class="pln"> l_step </span><span class="pun">+</span><span class="pln"> </span><span class="lit">1</span><span class="pun">))));</span><span class="pln"><br/>   </span><span class="kwd">END</span><span class="pln"> LOOP</span><span class="pun">;</span><span class="pln"><br/>  UTL_SMTP</span><span class="pun">.</span><span class="pln">write_data</span><span class="pun">(</span><span class="pln">l_connection</span><span class="pun">,</span><span class="pln"> crlf</span><span class="pun">);</span><span class="pln"><br/>   </span><span class="kwd">End</span><span class="pln"> Loop</span><span class="pun">;</span><span class="pln"><br/>   </span><span class="kwd">End</span><span class="pln"> Loop</span><span class="pun">;</span><span class="pln"><br/><br/>   </span><span class="com">----------------------------------------------------</span><span class="pln"><br/>   </span><span class="com">-- Write the final html boundary</span><span class="pln"><br/>  utl_smtp</span><span class="pun">.</span><span class="pln">write_data</span><span class="pun">(</span><span class="pln">l_connection</span><span class="pun">,</span><span class="pln"> <br/>  crlf </span><span class="pun">||</span><span class="pln"> </span><span class="str">'--'</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> l_boundary </span><span class="pun">||</span><span class="pln"> </span><span class="str">'--'</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> crlf</span><span class="pun">);</span><span class="pln"><br/>   </span><span class="com">----------------------------------------------------</span><span class="pln"><br/>   </span><span class="com">-- Close the connection and end</span><span class="pln"><br/>  utl_smtp</span><span class="pun">.</span><span class="pln">close_data</span><span class="pun">(</span><span class="pln">l_connection</span><span class="pun">);</span><span class="pln"> <br/>  utl_smtp</span><span class="pun">.</span><span class="pln">quit</span><span class="pun">(</span><span class="pln"> l_connection </span><span class="pun">);</span><span class="pln"><br/>  dbms_lob</span><span class="pun">.</span><span class="pln">freetemporary</span><span class="pun">(</span><span class="pln">l_body_html</span><span class="pun">);</span><span class="pln"><br/></span><span class="kwd">end</span><span class="pun">;</span>


A sample "p_html" field looks like this:

<span class="pun"><</span><span class="pln">p</span><span class="pun">></span><span class="pln"><br/>  Text </span><span class="kwd">right</span><span class="pln"> before the image</span><span class="pun">.</</span><span class="pln">p</span><span class="pun">></span><span class="pln"><br/></span><span class="pun"><</span><span class="pln">p</span><span class="pun">></span><span class="pln"><br/>   </span><span class="pun"><</span><span class="pln">img alt</span><span class="pun">=</span><span class="str">"HarryPotter"</span><span class="pln"> src</span><span class="pun">=</span><span class="str">"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAoHBwkHBgoJCAkLCwoMDxkQDw4ODx4WFxIZJCAmJSMgIyIoLTkwKCo2KyIjMkQyNjs9QEBAJjBGS0U+Sjk/QD3/2wBDAQsLCw8NDx0QEB09KSMpPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT3/wAARCACxARkDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMn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Yu2P/ACEZvr/Wug0//j1k/wCuJooqY7kS2M+P7p+lFFFWSf/Z"</span><span class="pln"> </span><span class="pun">/></</span><span class="pln">p</span><span class="pun">></span><span class="pln"><br/></span><span class="pun"><</span><span class="pln">p</span><span class="pun">></span><span class="pln"><br/>  Text </span><span class="kwd">right</span><span class="pln"> after the image</span><span class="pun">.</</span><span class="pln">p</span><span class="pun">></span>

Tagged:

Answers

  • Saubhik
    Saubhik Member Posts: 5,805 Gold Crown

    This thread may help you.

  • PhilMan2
    PhilMan2 Member Posts: 380 Bronze Badge

    Hi,

    I looked at this thread and its links.  It doesn't help, unfortunately.  I'm still looking for an answer of how to send an embedded image in the body of an html eMail using UTL_SMTP.

    Has anyone had any experience with this?

    Phil

  • Stako Botev
    Stako Botev Member Posts: 184

    Hi,

    Have you considered that this could be due to your e-mail client?

    I just tried your sample message body with the embedded image in it - I sent it through Oracle UTL_SMTP and received it successfully on my local e-mail client.

    The image was fine and displayed as normal picture. However when I sent the same email on my gmail account, the picture was not shown.

    So this is most probably due to configuration of the mail client.

    Cheerz,

    Stako

  • PhilMan2
    PhilMan2 Member Posts: 380 Bronze Badge

    Hi 2772777.  Thanks for looking at this.  I really appreciate it.

    I get similar results when I switch to my hotmail account.  I retrieve the eMail using Outlook 2013 as well as through a FIrefox browser to outlook.com.  All attempts do NOT show the image.  I'm wondering if it's the way I'm calling UTL_SMTP.

    The code that actually sends html body of the eMail is:

    ----------------------------------------------------
    -- Send the email body 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;
    --The following crlf is necessary after the body is written
    utl_smtp.write_data(l_connection, crlf);
    ----------------------------------------------------

    Any ideas?  Again, thanks for your help.

    Phil

  • Billy Verreynne
    Billy Verreynne Software Engineer Member Posts: 28,834 Red Diamond

    If you create a valid MIME body as per RFC specifications, it will render correctly in the vast majority (if not all), of e-mail clients.

  • PhilMan2
    PhilMan2 Member Posts: 380 Bronze Badge

    Hi Billy.  Thanks for replying.  I looked at the link you provided.  I'm trying to figure out where the body I'm sending is not a valid MIME body.  Is there some sort of validation site that can tell me what's improper about my current message?

    Thanks for your help.

    Phil

  • Billy Verreynne
    Billy Verreynne Software Engineer Member Posts: 28,834 Red Diamond

    No. Not that I'm aware of.

    When creating e-mail bodies, I prefer to letting an e-mail client do it for me. I will use my e-mail client, create the type of e-mail I want, and then mail it to myself. I'll then view the incoming e-mail in its raw format and use that as a template for my code.

    Just keep in mind that not all mail clients and mail servers are equal. MS Exchange for example for some idiotic reason rips the raw e-mail apart and rewrites the entire thing - to the extent of replacing your boundary tags with its boundary tags, and base64 encoding plain/text MIME areas. So do not expect your e-mail to arrive in the actual format that you send it. Which is why it is best to ensure your e-mail is as vanilla MIME as possible. 

This discussion has been closed.