5 Replies Latest reply: Mar 8, 2013 4:46 AM by BluShadow RSS

    embeded image in email body in pl/sql

    611282
      Hi, i need to embend images in the email body.
      Someone have an example?
      Thankls
        • 1. Re: embeded image in email body in pl/sql
          770799
          wich db you're using?

          are you using utl_mail or utl_smtp?
          • 2. Re: embeded image in email body in pl/sql
            611282
            i m using oracle 10g
            and we are using utl_smtp
            • 3. Re: embeded image in email body in pl/sql
              Billy~Verreynne
              The best example is looking at a raw e-mail (also called a Mime body) to see how it is formatted when attaching an image to an e-mail.
              Subject: Sample mail with image
              From: "John Doe" <john.doe@some-domain.com>
              To: "Jane Doe" <jane.doe@some-domain.com>
              Content-Type: multipart/mixed; boundary="=-OUaFMF/w0kLpDLyh5tDD"
              Mime-Version: 1.0
              
              --=-OUaFMF/w0kLpDLyh5tDD
              Content-Type: text/plain
              Content-Transfer-Encoding: 7bit
              
              This is the body of the e-mail message. Attached is small 1.4kb image.
              
              --=-OUaFMF/w0kLpDLyh5tDD
              Content-Disposition: inline; filename="talk.gif"
              Content-Type: image/gif; name="talk.gif"
              Content-Transfer-Encoding: base64
              
              R0lGODlhIAAgAOcAADQyNBSGzISGhPzGBITalMTGxMTuzPwKJPy2BPzmjOTm5ARyxAS2JISChPzW
              hIS65OT25PyKlHSy3FxeXMza1PxOZMTCxExKTPwyTPT29NSCnPzG1KSmpEzKZJSWlKzStHRydPwa
              NPzyrPzy1CS+PPyarNTW1PT+9LS2tLTW7Dw+PESa1Nzy3PxqfGzSfKTetPziVPwSLPyuZPzupAx+
              xPzejPySnGxqbPz2/Px6lIyOjPzOBMzOzPy+BPzmpOzu7BS6NPxidPyqvFRWVOTi5KyurJyenNze
              3LTmxDw6PDSS1Mzm9BR6xOz67PyOpHy23GRmZMTe9Pw6TPT69FzOdHx6fPTy9DTCTNzW5Ly+vERG
              RGSq3Nzq9PxyhHzalKzmtPwWLPzipPy6xDQ2NByK1IyKjPzKBMzKzMzy1PwOLPy6BPzqjOzq7AR2
              xAy6LPzKrIy+5OT27PyOlHS23GRiZPxWbExOTPw2TPzO1KyqrFTKZJyanKzatPwiPPzyvCzCREym
              3PymtLy6vERCRHTOhBSCzJSSlNTS1By+PFxaXLSytKSipPxehOze5Pzu9Pz+/KTirPx+jPyutNza
              3Nzu/PxufPzijPyWnGxubPz6/PzSBPzCBPzqpOzy7MTi9Hx+fPT6/PwWNAAA2gAAAAAAAAAAAAAA
              AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
              AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
              AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
              AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
              AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAANoALAAAAAAgACAA
              AAj+AB8JHEiwYKaCCBMmzGSFDZtJJrCYmMQmg8KLAh8WUMSBQ54iRfJwUGTBhIKDGAf+OJPHiKCT
              BDPhYMMjTx5Bk1AqzIRlkQcLFhFmyvCj6CQOHlCw0UkQB48yi4ikfGSFiAI2BRp4OIKDaaZJn4z8
              mCowE5FJCg5VEXAkg042HsqwwSgChh8CepqAImKCyBkohioOPEPnkEA4gCghXKNpRgcGLB5lOmKS
              wxAUVgRm8NAA5RYySxbvcMwAwqM4Pw4dmUSngVSqdLIcXrCABhdJMUIEcZTADKfHLND8eQGRzZ4h
              ZwT+sHNEoCclNOY06sMoR4gSCQb8ZoCExB8kRA7+KUAxSPajHxdeP9oSILQQMdZL1NiU4DEJRGjM
              iregRdDBH0PwMBB7S+Bxxx0YXFdDDz504IYbHTSBA2Xj2WGBQFZUsceAhaRQyQEbBAKGEw6oEUYH
              V7jghhedFGfIDYZJVgQdCggkARMraJBGEBWkUYcMCJx4BRpUAMHHIWdhEthAkyiZWRQPPIDFJV3I
              EYENbzgwwheQTMECIR+gxQEIBbiFoSITcIDDI1Og5IhkaxpEAUUFVJGHYJopYEQiS041GRE/PMXB
              JJ3oxNBRE0xwJ0YzWWFFFoYUcUhFTBE1iQU6DKEFHQIIslMBhuwhiHhuGTrUD3xZwEEDdgwSJ6qd
              aS0iwB5FFGACG1aYaVAGVigwSQFF3ABFRg0AwKkRimShGhs/6GrQUFUdUoQKijyigA6DYEKrBcv+
              YEUmTAnV6yEg0IFVFVpUwYEgPBzBbAZrhitUBgrsMYYhOiTCJwoFYKFAs+CSVVYBgySByQ06oHDG
              srnKixG4JhixiMITHaGAow77ydAPDv3rqLMCxzRUBrzCm3HIKKesMkIBAQA7
              
              
              --=-OUaFMF/w0kLpDLyh5tDD--
              This is what you need to send via the DATA command to the SMTP server. As you can see, you need to send a multipart Mime message - as it contains text and image data.

              In the header you specify the boundary string that separates text from image. The image part has its own header. We recommend to the mail reader, to display the image in-line. We also tell it the format (gif image) and file name. Lastly we tell the mail reader that the image in base64 ("+special character+") format. Why that format? It is risky to send binary data across systems - as our systems binary representation can be different from the intermediate and end systems that will handle this mail. For example, we could be using little-endian and the mail server big-endian. Sending binary data in our little-endian format will be corrupted. Thus we convert the binary data (using base64) to a safer character format and send it in that format.

              The mail reader has the intelligence to convert that to an image using its binary system - and display it.

              I suggest that you simply play around with the above Mime payload and send it to your e-mail address using UTL_SMTP in PL/SQL.

              Mime standards are described in RFC (Request For Comments) specifications. Have a look at http://www.ietf.org/rfc.html for Multipurpose Internet Mail Extensions (MIME) RFC's 1341 and 1521 - 1523.

              Note that your code needs to construct a valid Mime body.. SMTP is simply the protocol that delivers that for you. It is the truck that delivers the cargo. You need to create that cargo, or use something primitive like UTL_MAIL to create that cargo for you (though UTL_MAIL lacks in several respects and can only create basic Mime bodies).
              • 4. Re: embeded image in email body in pl/sql
                995463
                HI,

                please see my code want to add image in mail body .

                 V_CLOB := '<html>
                   <head>
                     <title>Test HTML with Embedded Image</title>
                   </head>
                   <body>
                     <h1>Test HTML with Embedded Image</h1>
                     <p>And here it is:</p>
                     <img src="data:image/gpg;base64,'; 
                 
                  get_enc_img_from_tab (922,l_clob);
                  
                  insert into ANUP(MAILID)VALUES(blob_to_clob(l_clob));
                 
                  V_CLOB := blob_to_clob(V_BLOB) ||'" alt="Site Logo" />
                  <p>The end.</p>
                  </body>
                  </html>'; 
                
                  /* THIS IF CONDITION DENOTED FOR PLAIN TEXT NOT FOR HTML TEXT*/
                  IF V_HTML_TEXT IS NOT NULL THEN
                    UTL_SMTP.WRITE_DATA(V_MAIL_CONN, '--' || V_BOUNDARY || UTL_TCP.CRLF);
                   UTL_SMTP.WRITE_DATA(V_MAIL_CONN, 'Content-Type:text/html; charset="iso-8859-1"' || UTL_TCP.CRLF || UTL_TCP.CRLF);
                    UTL_SMTP.WRITE_DATA(V_MAIL_CONN,V_CLOB);
                    UTL_SMTP.WRITE_DATA(V_MAIL_CONN, UTL_TCP.CRLF || UTL_TCP.CRLF);
                  END IF;
                Edited by: BluShadow on 08-Mar-2013 10:44
                added {noformat}
                {noformat} tags.  Please see {message:id=9360002} and learn to do this yourself in future.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
                • 5. Re: embeded image in email body in pl/sql
                  BluShadow
                  Couldn't you have continued on your own thread?

                  jpg file in mail body

                  ... where people are already talking to you, rather than hijack this old one?