In some situations, you may want to send e-mail to a user or a group of users who have not yet registered and who do not have profiles. For example, you might want to send a gift certificate to a group of e-mail addresses promising a promotion if the recipients register at your Web site. To send e-mail to a user without a profile, use the TemplateEmailInfoImpl.messageTo property. You can set the messageTo property globally, or in a JSP or JHTML file. If you set it globally, messageTo overrides the emailAddress property specified in the e-mail template. To set messageTo in a JSP file, add the following lines to the JSP template:

<dsp:setvalue paramvalue="message.profile.giftEmailAddress"
<setvalue param="fillfromTemplate" value="true">

Here is the same example in JHTML:

<setvalue param="messageTo"
<setvalue param="fillfromTemplate" value="true">

This setting is local to a specific template and does not affect other mailings. The fillfromTemplate parameter forces the sender to override any property set in the template file.

Using the TemplateEmailSender Class

You can also send e-mail to e-mail addresses that do not have matching profiles by specifying the e-mail addresses as an array of Strings. In the same way that you can send e-mail to a profile group, you can programmatically specify a list of e-mail addresses:

Object []recipients = {"", ""};
TemplateEmailSender.sendEmailMessage(TemplateEmailInfo, recipients);

In this example, the TemplateEmailSender component checks each element in the recipients [] and if the element is of type String , the TemplateEmailSender sends e-mail to the e-mail address.

You can also mix and match Profile objects with String based e-mail addresses when calling TemplateEmailSender.sendEmailMessage:

Object[] profileRecipients = profileGroup.getGroupMembers();
Object[] emailRecipients = {"", ""};
Object[] recipients = addArrays(profileRecipients, emailRecipients);
TemplateEmailSender.sendEmailMessage(TemplateEmailInfo, recipients);

For more information on working with users who don’t have profiles, see Tracking Guest Users in the Working with User Profiles chapter.