Sample JSP code: e-mail template

Use this sample JSP code snippet as a starting point to create custom e-mail templates for marketing e-mail activities. Creating a template using this JSP code snippet is an alternative to having business users create a template using the WebSphere Commerce Accelerator or Management Center user interface.

This procedure explains how to set up the e-mail activity template in the development environment so that business users can specify the e-mail template when creating e-mail activities using either Management Center or WebSphere Commerce Accelerator.

This procedure applies only to consumer direct and B2B direct store models.

This sample JSP code snippet is called the EmailMessageDisplay.jsp file and it is located at the following path:

  • WebSphere Commerce Developer WCDE_installdir/samples/emailactivity/web/EmailMessageDisplay.jsp

Creating a basic e-mail template using the sample JSP code for e-mail templates

  1. Make sure that e-mail activity accounts are configured for your site.
  2. Open WebSphere Commerce Developer and switch to the Enterprise Explorer view.
  3. Locate the EmailMessageDisplay.jsp file at this path:

    WCDE_installdir/samples/emailactivity/web/EmailMessageDisplay.jsp

  4. Copy the EmailMessageDisplay.jsp file to a folder in which you want to store the custom template, for example:

    WebSphere Commerce DeveloperWCDE_installdir/workspace/Stores/WebContent/StoreDirectory/include/

  5. You can rename the JSP file to something relevant to your marketing e-mail, for example, AbandonedCart.jsp.
  6. Register the JSP file as an e-mail activity template.
  7. Locate the EmailActivityText*.properties file at the following path:

    WCDE_installdir/samples/emailactivity/properties/

  8. WebSphere Commerce Developer Copy the content of the EmailActivityText*.properties file to your store's properties file in your store directory. The EmailActivityText*.properties file contains the strings that make up the content of the e-mail.

    For example, for the Madisons starter store, the storetext*.properties files are located here:

    WCDE_installdir/workspace/Stores/Java Resources: src/Madisons/

  9. Edit the strings as required to customize the content of the marketing e-mail.
  10. Restart the WebSphere Commerce server so that the changes take effect.
  11. Create a customer segment to target with the e-mail activity if an appropriate customer segment does not already exist.
  12. Create an e-mail activity and specify the new e-mail template using name you gave the new e-mail template when you registered it in a previous step. You can search for the e-mail template by this name.
  13. Test your e-mail activity to ensure the e-mail is successfully delivered.
  14. Deploy your changes to the production server.

Adding an e-Marketing Spot to an e-mail template

You can add an e-Marketing Spot to the template to display marketing information in the e-mail.

If you use WebSphere Commerce Accelerator to create e-mail activities, follow these steps:

  1. If you do not already have an e-Marketing Spot to use in the template, create one by completing these procedures:
  2. Take note of the emsName parameter value defined in the e-Marketing Spot JSP file because you must specify this value in the e-mail template JSP file later in this procedure.
  3. Create a Web activity using WebSphere Commerce Accelerator to display marketing content in the e-Marketing Spot.
  4. Open WebSphere Commerce Developer and switch to the Enterprise Explorer view.
  5. For B2B direct store models that are not Web 2.0 stores, complete the following substeps:
    1. If you do not already have an /include directory under your store's directory, create one. Here is an example of the location for this directory:
      • WebSphere Commerce Developer WCDE_installdir/ workspace/Stores/Web Content/StoreDirectory/include.
    2. Copy the JSP code snippet for e-Marketing Spots (WebSphere Commerce Accelerator), eMarketingSpotDisplay.jsp, from the following directory:
      • WCDE_installdir/samples/Snippets/web/Marketing/Campaigns
      to your store's /include directory.

    For other store models, the eMarketingSpotDisplay.jsp file should already exist in your store's /include directory.

  6. Edit the eMarketingSpotDisplay.jsp file that is in your store's /include directory.
  7. Find the following string; it should appear twice in the file:
    <%@ include file="../../ReusableObjects/AttachmentDisplay.jspf" %>
  8. Replace the string with this string:
    <%@ include file="AttachmentDisplay.jspf"%>
  9. Copy the AttachmentDisplay.jspf file from the following directory:
    • WCDE_installdir/samples/Snippets/web/ReusableObjects
    to your store's /include directory.
  10. Edit the e-mail template JSP file that you created.
  11. Delete the following two strings from the e-mail template JSP file:
    <%-- Remove this line to show e-Marketing Spot.
    -- Remove this line to show e-Marketing Spot. --%>
  12. Find the following string in the e-mail template JSP file:
    <c:param name="emsName" value="ESpot Name" />
  13. Replace the value ESpot Name with the value of the emsName parameter defined in the e-Marketing Spot JSP file.
  14. Save the e-mail template JSP file.
  15. To test your template, create an e-mail activity with WebSphere Commerce Accelerator and specify the e-mail template that you created.
  16. Deploy your changes to the production server.

If you use Management Center to create e-mail activities, follow these steps:

  1. If you do not already have an e-Marketing Spot to use in the template, create one by completing these procedures:
  2. Take note of the emsName parameter value defined in the e-Marketing Spot JSP file because you must specify this value in the e-mail template JSP file later in this procedure.
  3. Create a Web activity using Management Center to display marketing information in the e-Marketing Spot.
  4. Open WebSphere Commerce Developer and switch to the Enterprise Explorer view.
  5. For B2B direct store models that are not Web 2.0 stores, complete the following substeps:
    1. If you do not already have an /include directory under your store's directory, create one. Here is an example of the location for this directory:
      • WebSphere Commerce Developer WCDE_installdir/ workspace/Stores/WebContent/StoreDirectory/include.
    2. Copy the e-Marketing Spot code snippet for Management Center, WebServiceeMarketingSpotDisplay.jsp, from the following directory:
      • WCDE_installdir\samples\Snippets\web\Marketing\Campaigns
      to your store's /include directory.
    3. Rename the file from WebServiceeMarketingSpotDisplay.jsp to eMarketingSpotDisplay.jsp.
  6. Open the e-mail template JSP file to which you want to add the e-Marketing Spot.
  7. Delete the following two strings from the e-mail template JSP file:
    <%-- Remove this line to show e-Marketing Spot.
    -- Remove this line to show e-Marketing Spot. --%>
  8. Find the following string in the e-mail template JSP file:
    <c:param name="emsName" value="ESpot Name" />
  9. Replace the value ESpot Name with the value of the emsName parameter defined in the e-Marketing Spot JSP file.
  10. Save the e-mail template JSP file.
  11. To test your template, create an e-mail activity with Management Center and specify the e-mail template that you created.
  12. Deploy your changes to the production server.

Adding a content spot to an e-mail template

You can add a content spot to the e-mail template.

  1. If you do not already have a content spot to use in the template, create one by completing these procedures:
  2. Open WebSphere Commerce Developer and switch to the Enterprise Explorer view.
  3. Create a directory for the content spot under the store's directory, for example:
    • WebSphere Commerce Developer WCDE_installdir/workspace/Stores/WebContent/StoreDirectory/Snippets/Marketing/Content.
  4. Copy the content spot display code snippet, ContentSpotDisplay.jsp, from the following directory:
    • WCDE_installdir/samples/Snippets/web/Marketing/Content/
    to your store's /Snippets/Marketing/Content directory.
  5. Edit the ContentSpotDisplay.jsp file.
  6. Find the following string in the ContentSpotDisplay.jsp file. It should appear twice in the file:
    <%@ include file="../../ReusableObjects/AttachmentDisplay.jspf" %>
    and replace it with:
    <%@ include file="AttachmentDisplay.jspf"%>
  7. Copy the AttachmentDisplay.jspf file from the following directory:
    • WCDE_installdir/samples/Snippets/web/ReusableObjects
    to your store's /Snippets/Marketing/Content directory.
  8. Edit the e-mail template JSP file that you created.
  9. Find the following string in the e-mail template JSP file:
    <fmt:message key="EmailMessageDisplay_Para3" bundle="${emailMessageText}" />
  10. Above the string, insert:
    <c:import url="${sdb.jspPath}/Snippets/Marketing/Content/ContentSpotDisplay.jsp">
            <c:param name="spotName" value="ContentSpot Name" />
    </c:import>
  11. Replace the value ContentSpot Name with the value of the spotName parameter defined in the content spot JSP file.
  12. Save the e-mail template JSP file.
  13. To test your template, create an e-mail activity and specify the new e-mail template.
  14. Deploy your changes to the production server.