Thursday, January 31, 2013

Targeted Email : ATG

Creating Targeted E-mail

You create targeted e-mail using the atg.userprofiling.email.TemplateEmailInfoImpl class. This class draws the message body of an e-mail from a page template, invokes a MessageContentProcessor component to process the content, and then passes the resulting JavaMail object to the TemplateEmailSender component, which sends the message. The properties of a TemplateEmailInfoImpl object store values that are specific to an individual e-mail campaign, so you should create a separate instance of this class for each campaign.

You can use targeted e-mail to produce e-mail messages that are personalized for different profiles. The e-mail content is based on a JSP or JHTML template, specified with the templateURL property of a TemplateEmailInfoImpl object. Using the dynamic elements of the Page template, you can customize the e-mail for each of your users according to their profile attributes. Here is a JSP example :

<html>
<dsp:importbean bean="/atg/userprofiling/Profile"/>
<p>Dear <dsp:valueof bean="Profile.firstName">Customer</dsp:valueof>,
<p>We're writing to tell you about some exciting new offers ...
</html>



The template yields different message text depending on the attributes of the recipient’s profile. You can use ATG’s targeting servlet beans to personalize the content of the message as well. If the template page contains a targeting servlet bean, the servlet bean behaves just as it would in any other page, rendering content targeted to the current profile.

The TemplateEmailInfoImpl object contains the standard e-mail message attributes as properties. When it invokes the createMessage method, the specified e-mail attributes create and fill in a javax.mail.Message object, which can then be sent to the desired recipient using the TemplateEmailSender service

Note that TemplateEmailInfoImpl is a subclass of the abstract class TemplateEmailInfo. If you want to create your own template e-mail implementation, you can create a subclass of TemplateEmailInfo that implements all of its methods, and use it as you would use TemplateEmailInfoImpl.



Creating a Targeted E-mail Template

The page template for your targeted e-mail is specified by the templateURL property of the TemplateEmailInfoImpl object. You create this template like any other page. Because the template page is passed to the standard ATG servlet pipeline, it can include ATG servlet beans and additional JHTML or JSP tags.

Here is a sample JSP targeted e-mail template. It displays a few profile attributes and contains a targeting servlet bean. Assuming the targeting rules used in the TargetingForEach servlet bean’s targeter service depend on the attributes of the Profile component, the targeting results displayed in the e-mail message will be different for each profile.

<dsp:importbean bean="/atg/userprofiling/Profile"/>
<p>Dear <dsp:valueof bean="Profile.firstName"/>
<dsp:valueof bean="Profile.lastName"/>,


<p>Thank you for your order! It has been shipped today to:

<blockquote><pre>
<dsp:valueof bean="Profile.address"/><br>
<dsp:valueof bean="Profile.city"/>, <dsp:valueof bean="Profile.State"/>
<dsp:valueof bean="Profile.zipCode"/>
</pre></blockquote>

<p>Since your last order, we've introduced some great new products. If you enjoy
your new <dsp:valueof bean="Profile.lastProductShipped"/>, you may also be
interested in ordering some of these great widgets:
<p>

<dsp:droplet name="/atg/targeting/TargetingForEach">
  <dsp:param bean="/targeters/WidgetTargeter" name="targeter"/>
  <dsp:oparam name="output">
    <dsp:valueof param="element.name"/><br>
  </dsp:oparam>
</dsp:droplet>

<p>Thank you for shopping with us.

<p>Sincerely,
The Customer Service Team
help@example.com
http://www.example.com


Note that if your template page contains links to other URLs on your site, you must specify them as absolute URLs; otherwise the e-mail recipients will not be able to access the linked pages. Use the full http://server:port/... form of the URL. For example, in JSP code:

<dsp:img src="http://myserver:80/images/logo.gif">
<dsp:a href="http://myserver:80/help/index.html">help</dsp:a>


The following example will not work, because it uses relative URLs:

<dsp:img src="images/logo.gif">
<dsp:a href="help/index.html">help</dsp:a>


Specifying E-mail Fields in the Template

By default, the Personalization module takes the values for various fields of an e-mail message from properties of the TemplateEmailInfoImpl object. This behavior means that all messages using the same object will have identical properties. For example, suppose the value of the messageSubject property of the TemplateInfoImpl component is “Hello”. All e-mail messages created by this component will contain the subject line “Hello”.

You can override the values of these properties in a specific e-mail template by doing the following:

In the template, include parameters with the same names as the corresponding TemplateEmailInfoImpl properties.

Set the fillFromTemplate value of the TemplateEmailInfoImpl object to true.

For example, you can set a different subject line for a specific mailing by including a statement as follows in the template for that mailing:


JSP example:
<dsp:setvalue value="Your order has shipped" param="messageSubject"/>

JHTML example:

<setvalue param="messageSubject" value="Your order has shipped">

Because these parameters are evaluated for each message individually, they can include dynamic content. For example, you could set the message subject as follows.


JSP example:

<dsp:setvalue value='<%="Order " + request.getParameter("order.id")+
" has shipped"%>' param="messageSubject"/>


JHTML example:

<setvalue param="messageSubject"
  value="Order 'request.getParameter("order.id")' has shipped">


There are seven parameters that you can use in this way to override the corresponding TemplateEmailInfoImpl properties:

mailingName

messageFrommessageTo

messageReplyTo

messageSubject

messageCc

messageBcc



You can use any combination of these parameters in an e-mail template; if any of these parameters is not set, the system uses the corresponding property value instead.

For example, you could globally set the messageCc property to Cc yourself, but you could override this property if you wanted to Cc or Bcc other people to make them aware of a particular e-mail campaign. The messageCc and messageBcc parameters are defined as a string of e-mail addresses separated by commas. For example, you could add the following lines to a template file.


JSP example:

<dsp:setvalue value=lewis@example.com,everyone@example.com
 param="messageCc"/>
<dsp:setvalue value=management@example.com,bob@example.com
 param="messageBcc"/>


JHTML example:

<setvalue param="messageCc" value=lewis@example.com,everyone@example.com>
<setvalue param="messageBcc" value=management@example.com,bob@example.com>



Note: Property values you set through an e-mail template are not persisted to the database. Only the values that are set in the TemplateEmailInfoImpl object are persisted.



No comments:

Popular Posts