Creating an Email from Rich Text Editor Output

The following example creates an email message using output from a long edit box enabled with the rich text editor. Using the ParseRichTextHtml method, rich text output of the long edit box is split into an array of MCFBodyPart objects.

import PT_MCF_MAIL:*;

Local PT_MCF_MAIL:MCFOutboundEmail &email = create PT_MCF_MAIL:MCFOutboundEmail();
Local PT_MCF_MAIL:MCFMultipart &mp = create PT_MCF_MAIL:MCFMultipart();
Local PT_MCF_MAIL:MCFMailUtil &mu = create PT_MCF_MAIL:MCFMailUtil();

Local string &htmlText = RECORD_NAME.FIELD_NAME.Value;

&mp.SubType = "related";
&email.Recipients = &recipients;
&email.From = &from;
&email.Subject = "Your Order";

Local array of PT_MCF_MAIL:MCFBodyPart &bp;
&mu.imagesLocation = "c:\temp\images";
&bp = &mu.ParseRichTextHtml(&htmlText);

If (&bp = Null) Then
   MessageBox(0, "", 0, 0, &mu.ErrorDescription);
   Return;
End-If;

&mp.AddBodyPart(&bp [1]);

For &i = 2 To &bp.Len
   &mp.AddBodyPart(&bp [&i]);
End-For;

&email.MultiPart = ∓
Local integer &resp = &email.Send();

/* Exec code to check the &resp for the result */

/* Exec code to delete temporary image files from the imagesLocation directory */

For example, the rich text editor is used to create a message containing text and two images as shown in this example:

This example illustrates the fields and controls on the Rich text editor displaying an example email. You can find definitions for the fields and controls later on this page.

Rich text editor displaying an example email

The HTML for this email is as follows:

<p>Dear Customer,</p>
<p>Here are the details of your order:</p>
<ul> 
<li> Item #1 - Ocean Sunset:
<br /> <img height="180" id="PT_RTE_IMG_DB_LOC###20091111142435187⇒
Sunset_thumbnail.jpg" src="/cs/QEDMO/cache/PTRTDB_JPG_GIYDAOJRGEYT⇒
CMJUGI1DGNJRHA2VG4LOONSXIX2UNB1W1YTOMFUWYLTKOBTQ=_GA==_GE==_2000000000.⇒
JPG" width="240" /><br /> &nbsp;</li> 
<li> Item #2 - Hazy Blue Mountains:
<br /> <img height="180" id="PT_RTE_IMG_DB_LOC###20091111142508395⇒
Mountains_thumbnail.jpg" src="/cs/QEDMO/cache/PTRTDB_JPG_GIYDAOJRGEYTCM⇒
JUGI1TAOBTHE1U122VNZ1GC1LOONPXI1DVNVRG3YLJNQXGU3DH_GA==_GE==_2000000000.⇒
JPG" width="240" /></li>
</ul>
<p>Thank you and regards,</p>
<p>Customer Service Department
<br /><a href="http://www.xyzcorp.com">http://www.xyzcorp.com</a></p> 

When this HTML is parsed by the ParseRichTextHtml method, an array with three MCFBodyPart elements is created. The first MCFBodyPart is array element &bp [1] with the following properties:

  • &bp [1].ContentType =

    text/html
    
  • &bp [1].Text =

    <p>Dear Customer,</p>
    <p>Here are the details of your order:</p>
    <ul> 
    <li> Item #1 - Ocean Sunset:
    <br /> <img height="180" id="PT_RTE_IMG_DB_LOC###20091111142435187⇒
    Sunset_thumbnail.jpg" src="cid:2205@pc27" width="240" />
    <br /> &nbsp;</li> 
    <li> Item #2 - Hazy Blue Mountains:
    <br /> <img height="180" id="PT_RTE_IMG_DB_LOC###20091111142508395⇒
    Mountains_thumbnail.jpg" src="cid:8160@pc27" width="240" /></li>
    </ul>
    <p>Thank you and regards,</p>
    <p>Customer Service Department
    <br /><a href="http://www.xyzcorp.com">http://www.xyzcorp.com</a></p> 
    

The second MCFBodyPart is array element &bp [2] with the following properties:

  • &bp [2].ContentType =

    image/gif
    
  • &bp [2].Description =

    Image1
    
  • &bp [2].Disposition =

    inline
  • &bp [2].AttachmentURL =

    c:\temp\images/20091111142435187Sunset_thumbnail.jpg

The final MCFBodyPart is array element &bp [3] with the following properties:

  • &bp [3].ContentType =

    image/gif
    
  • &bp [3].Description =

    Image2
    
  • &bp [3].Disposition =

    inline
  • &bp [3].AttachmentURL =

    c:\temp\images/20091111142508395Mountains_thumbnail.jpg

Observe that the email received by the recipient is formatted the way that it appeared in the rich text editor as shown in the following example:

This example illustrates the fields and controls on the Email as received in Microsoft Outlook. You can find definitions for the fields and controls later on this page.

Email as received in Microsoft Outlook

Finally, the XML code that represents this email message is as follows:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:⇒
cms="http://cms.ocs.oracle/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/⇒
envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
   <SOAP-ENV:Body>
      <cms:GetEntitySnapshotResponse>
         <return xsi:type="EmailMessageType_DEBUG" SnapshotId="00000000000000010⇒
00009E2607E2B4200000124E528DD580000000000000001" CEN="334B:3BF0:emsg:⇒
38893C00F42F38A1E0404498C8A6612B0000FEE32642">
            <CreatedOn>2009-11-11T21:31:07Z</CreatedOn>
            <Creator EID="334B:3BF0:user:CB3F97695BD24114B65149D2E4CC842E0000000⇒
112AE"/>
            <Deleted>false</Deleted>
            <ModifiedBy EID="334B:3BF0:user:CB3F97695BD24114B65149D2E4CC842E0000⇒
000112AE"/>
            <ModifiedOn>2009-11-11T21:31:07Z</ModifiedOn>
            <Name>your order</Name>
            <Parent EID="334B:3BF0:afrh:38893C00F42F38A1E0404498C8A6612B00001EF9⇒
C00A"/>
            <New>false</New>
            <ReadFlag>true</ReadFlag>
            <UserCreatedOn>2009-11-11T21:31:06Z</UserCreatedOn>
            <Viewer EID="334B:3BF0:user:CB3F97695BD24114B65149D2E4CC842E00000001⇒
12AE"/>
            <Content>
               <ContentId>24316678.11257950022359.JavaMail.admin@XXXXX</ContentId>
               <MediaType>message/rfc822</MediaType>
               <Body xsi:type="MultiContentType">
                  <MediaType>multipart/related</MediaType>
                  <Parts>
                     <Item xsi:type="SimpleContentType">
                        <MediaType>text/html</MediaType>
                        <CharacterEncoding>us-ascii</CharacterEncoding>
                        <Language>en</Language>
                        <ContentStream>
                           <Id>T0RNMU5ESTFOVFpEUmtKQ05FWTJNemhETmpWQ1JqWXdRel⇒
ZDT0VJek9EUXdNREF3TURBd01EWTVRVUU9JCQjIyQkN2JpdCQkIyMkJDg3NyQkIyMkJDU2Mg==</Id>
                           <Length>640</Length>
                        </ContentStream>
                     </Item>
                     <Item xsi:type="SimpleContentType">
                        <Disposition>INLINE</Disposition>
                        <ContentId>&lt;2205@pc27&gt;</ContentId>
                        <MediaType>image/gif</MediaType>
                        <CharacterEncoding>ascii</CharacterEncoding>
                        <Language>en</Language>
                        <ContentStream>
                           <Id>T0RNMU5ESTFOVFpEUmtKQ05FWTJNemhETmpWQ1JqWXdRelZD⇒
T0VJek9EUXdNREF3TURBd01EWTVRVUU9JCQjIyQkYmFzZTY0JCQjIyQkMTY3NCQkIyMkJDExNzI4</Id>
                           <Length>11923</Length>
                        </ContentStream>
                        <Name>20091111142435187Sunset_thumbnail.jpg</Name>
                     </Item>
                     <Item xsi:type="SimpleContentType">
                        <Disposition>INLINE</Disposition>
                        <ContentId>&lt;8160@pc27&gt;</ContentId>
                        <MediaType>image/gif</MediaType>
                        <CharacterEncoding>ascii</CharacterEncoding>
                        <Language>en</Language>
                        <ContentStream>
                           <Id>T0RNMU5ESTFOVFpEUmtKQ05FWTJNemhETmpWQ1JqWXdRelZD⇒
T0VJek9EUXdNREF3TURBd01EWTVRVUU9JCQjIyQkYmFzZTY0JCQjIyQkMTM2NDMkJCMjJCQ3MzUy</Id>
                           <Length>7553</Length>
                        </ContentStream>
                        <Name>20091111142508395Mountains_thumbnail.jpg</Name>
                     </Item>
                  </Parts>
               </Body>
               <From>
                  <Address>&lt;psft@example.com&gt;</Address>
               </From>
               <Priority>NONE</Priority>
               <Sender>
                  <Address>&lt;psft@example.com&gt;</Address>
               </Sender>
               <SentDate>2009-11-11T21:31:06Z</SentDate>
               <Size>21039</Size>
               <Subject>Your Order</Subject>
               <TOReceivers>
                  <Item>
                     <Address>&lt;&gt;</Address>
                     <Participant EID="334B:3BF0:user:CB3F97695BD24114B65149D2E4⇒
CC842E0000000112AE"/>
                     <Directives/>
                     <Status>DELIVERED</Status>
                  </Item>
               </TOReceivers>
            </Content>
            <DeliveredTime>
               <DateOnly>false</DateOnly>
               <FloatingTime>false</FloatingTime>
               <Timestamp>2009-11-11T21:31:07Z</Timestamp>
            </DeliveredTime>
            <Modifiable>false</Modifiable>
            <ReceiptRequested>false</ReceiptRequested>
            <Type>EMAIL</Type>
            <MimeHeaders>
               <Item>
                  <Name>X-AUTH-TYPE</Name>
                  <Value>SW50ZXJuYWwgSVA=</Value>
               </Item>
               <Item>
                  <Name>Received</Name>
                  <Value>ZnJvbSByZ21pbmV0MTMub3JhY2xlLmNvbSAoLzE0OC44Ny4xM⇒
TMuMTI1KSBieSBkZWZhdWx0IChPcmFjbGUgQmVlaGl2ZSBHYXRld2F5IHY0LjApIHdpdGggRVNN⇒
VFAgOyBXZWQsIDExIE5vdiAyMDA5IDEzOjMxOjA2IC0wODAw</Value>
               </Item>
               <Item>
                  <Name>Received</Name>
                  <Value>ZnJvbSBCVUZGWSAoYnVmZnkudXMub3JhY2xlLmNvbSBbMTAuMTM4L⇒
jIyOC4xMzNdKSBieSByZ21pbmV0MTMub3JhY2xlLmNvbSAoU3dpdGNoLTMuMy4xL1N3aXRjaC0⇒
zLjMuMSkgd2l0aCBFU01UUCBpZCBuQUJMVjZVSjAxMzk0NiBmb3IgPGRhdmUucGllcmNlQG9yYWNsZ⇒
S5jb20+OyBXZWQsIDExIE5vdiAyMDA5IDIxOjMxOjA2IEdNVA==</Value>
               </Item>
               <Item>
                  <Name>MIME-Version</Name>
                  <Value>MS4w</Value>
               </Item>
               <Item>
                  <Name>To</Name>
                  <Value>ZGF2ZS5waWVyY2VAb3JhY2xlLmNvbQ==</Value>
               </Item>
               <Item>
                  <Name>MESSAGE-ID</Name>
                  <Value>PDI0MzE2Njc4LjExMjU3OTUwMDIyMzU5LkphdmFNYWlsLmFkb⇒
WluQEJVRkZZPg==</Value>
               </Item>
               <Item>
                  <Name>Content-Type</Name>
                  <Value>bXVsdGlwYXJ0L3JlbGF0ZWQ7ICBib3VuZGFyeT0iLS0tLT1fUGFyd⇒
F8xXzIzNzUyMTguMTI1Nzk1MDAyMjEwOSI=</Value>
               </Item>
               <Item>
                  <Name>From</Name>
                  <Value>cHNmdEBwZW9wbGVzb2Z0LmNvbQ==</Value>
               </Item>
               <Item>
                  <Name>X-SOURCE-IP</Name>
                  <Value>YnVmZnkudXMub3JhY2xlLmNvbSBbMTAuMTM4LjIyOC4xMzNd</Value>
               </Item>
               <Item>
                  <Name>X-CT-REFID</Name>
                  <Value>c3RyPTAwMDEuMEEwOTAyMDQuNEFGQjJEMTkuMDBGQSxzcz0xLGZncz⇒
0w</Value>
               </Item>
               <Item>
                  <Name>Subject</Name>
                  <Value>WW91ciBPcmRlcg==</Value>
               </Item>
               <Item>
                  <Name>Date</Name>
                  <Value>V2VkLCAxMSBOb3YgMjAwOSAyMTozMTowNiBHTVQ=</Value>
               </Item>
            </MimeHeaders>
         </return>
      </cms:GetEntitySnapshotResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>