3 Replies Latest reply on Jan 20, 2015 9:27 PM by user10220526

    Html Formatted Email In Email Activity in BPEL SOA 11g

    2700980

      Hi. I want to send Html formatted email using email activity . i am assigning the following expression to the contentBody variable of email.

      <%ora:toCDATA("<h2>")+bpws:getVariableData('inputVariable','payload','/client:process/client:input')+ora:toCDATA("</h2>")%>


      I email i am getting NaN. Do anybody knows how can i send formatted emails??? I am using JDEV 11.1.1.7 with soa 11g bpel 1.1

       

      -Thanks

        • 1. Re: Html Formatted Email In Email Activity in BPEL SOA 11g
          Martien van den Akker

          HI,

           

          Today I worked on this myself, since I needed it on my project as well. What I did was the following.

          I created an html message as follows:

          <assign name="CreateHtmlMessageAsString">
                              <copy>
                                  <from>concat("&lt;html&gt;&lt;body&gt;&lt;h1&gt;Reply on message  ",$umsSubject, "&lt;/h1&gt;&lt;br /&gt;Dit mailtje is &lt;em&gt;gegenereerd&lt;/em&gt;!&lt;br/&gt; Het heeft niet veel zin hier op te antwoorden.&lt;br/&gt; &lt;strong&gt;mooi he?&lt;/strong&gt;&lt;/body&gt;&lt;/html&gt;")</from>
                                  <to>$InvokeBase64Encode_process_InputVariable.payload/ns9:input</to>
                              </copy>
                          </assign>
          
          

          Then I created a bpel process to do an Base64 encode, using an embedded java. I could have done it in my main process, but this allowed me to test it seperately.

          The embedded java is as follows:

           

          <extensionActivity>
                <bpelx:exec name="B64EncodePayload" language="java">
                  <![CDATA[//Get the string from the variable 
          String htmlPayloadAsString = (String)getVariableData("htmlPayloadAsString");  
          htmlPayloadAsString = htmlPayloadAsString.replaceAll("&lt;", "<");
          htmlPayloadAsString = htmlPayloadAsString.replaceAll("&gt;", ">");
          htmlPayloadAsString = htmlPayloadAsString.replaceAll("&quot;", "\"");
          htmlPayloadAsString = htmlPayloadAsString.replaceAll("&amp;", "&");
          addAuditTrailEntry("HTML Payload is: " + htmlPayloadAsString);    
          // Encode the payload 
          Base64Encoder encoder = new Base64Encoder(); 
          try   
          {   
            String encodedString = encoder.encode(htmlPayloadAsString); 
            addAuditTrailEntry("B64 encoded string is: " + encodedString); 
            setVariableData("b64EncodedString", encodedString);
          }   
          catch(Exception e)  
          {  
            addAuditTrailEntry("Failed to encod string: " + e.getMessage() + "\nCaused by:" + e.getCause()); 
          }
          // Set the result in the variable]]>
                </bpelx:exec>
              </extensionActivity>
          
          

           

          You see that I do a replace of the encoded xml characters like '<', '>', '&' etc. Don't know if it's really necessary.

           

          I configured my email adapter to use an Opaque schema, that's why I needed to Base64 encode the string.

          The result of the base64 encoding together with the emailaddress and subject has to be assigned to the input variable as follows:

            <assign name="AssignMailProperties">
                              <copy>
                                  <from>$InvokeBase64Encode_process_OutputVariable.payload/ns9:result</from>
                                  <to>$InvokeSWKOutboundEmail_SendNotification_InputVariable.body/ns4:opaqueElement</to>
                              </copy>
                              <copy>
                                  <from>concat("In reply to: ", $umsSubject)</from>
                                  <to>$subjectTo</to>
                              </copy>
                              <copy>
                                  <from>"martien.van.den.akker@whereveriam.com"</from>
                                  <to>$outboundTo</to>
                              </copy>
                          </assign
          
          

          >

           

          Lastly: the trick was to invoke the email service as follows:

          <invoke name="InvokeSWKOutboundEmail" partnerLink="SWKOutboundEmail" portType="ns7:SendNotification_ptt"
                                  operation="SendNotification"
                                  inputVariable="InvokeSWKOutboundEmail_SendNotification_InputVariable" bpelx:invokeAsDetail="no">
                              <bpelx:toProperties>
                                  <bpelx:toProperty name="jca.ums.to" variable="outboundTo"/>
                                  <bpelx:toProperty name="jca.ums.subject" variable="subjectTo"/>
                                  <bpelx:toProperty name="jca.ums.msg.content-type">"text/html"</bpelx:toProperty>
                              </bpelx:toProperties>
                          </invoke>
          
          

          Where I gave in the property "jca.ums.msg.content-type" set to "text/html".

           

          Now I get Html formatted email.

           

          Hope this works for you.

           

          Regards,
          Martien

          • 2. Re: Html Formatted Email In Email Activity in BPEL SOA 11g
            Robert van Mölken

            You are using the right function, but you are using it wrong. You are doing a concat without using the string function for that, plus sign doens't work here.

             

            <%ora:toCDATA("<h2>")+bpws:getVariableData('inputVariable','payload','/client:process/client:input')+ora:toCDATA("</h2>")%>


            Should be:

             

            <%ora:toCDATA(concat("<h2>", bpws:getVariableData('inputVariable','payload','/client:process/client:input'), "</h2>"))%>


            Hopes that does the trick.


            Regards,

            Robert

            • 3. Re: Html Formatted Email In Email Activity in BPEL SOA 11g
              user10220526

              I was able to use the following tags to send the HTML formatted email correctly in SOA11g, try it out does not require any other changes.

               

              <copy>

                      <from expression="concat(string('&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml">&lt;head>&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;/>&lt;/head>&lt;body>&lt;table width=&quot;800&quot; border=&quot;0&quot; align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>&lt;tr>&lt;td height=&quot;25&quot; align=&quot;center&quot; bgcolor=&quot;#F7F7F7&quot;>&lt;font size=3 color=333399 face=Verdana> Process invalid record &lt;/td>&lt;/tr> &lt;tr>&lt;td>  &lt;/td>&lt;/tr> &lt;tr>&lt;td>&lt;font size=3 color=333399 face=Verdana>&lt;br>Invalid record updating Datebase. &lt;br>&lt;br>&lt;font size=3 color=333399 face=Verdana>The table cannot be updated in database for record-id 12345 at Date-Time: '),xp20:current-dateTime(),string(' for BPEL with Instance Id: '),ora:getInstanceId(),string('&lt;/font>&lt;/body>&lt;/html>'))"/>

                      <to variable="Invoke_emailNotification_InputVariable"

                          part="EmailPayload"

                          query="/EmailPayload/ns1:Content/ns1:ContentBody"/>

                    </copy>