Hi guys,
Today I took my first crack at using the CB 3.0 MailService plugin. First off, this plugin is awesome! I was able to get it up and running without a hitch. (more or less) I’ve implemented a custom interceptor to send an email to a user after an contact entry is logged to the database. announceInterception(‘onContactCreate’) fires successfully and hits the following method:
/**
-
@interceptionPoint
*/
function onContactCreate(event,interceptData){
var rc = event.getCollection();
log.info("--------onContactCreate-----------");
rc.emailView = “emails/contactRequest”;
rc.emailBody = getPlugin(“Renderer”).renderLayout(“Layout.Email”);
// Get new mail object
rc.mail = mailService.newMail().config(from=getSetting(‘email’).from,
replyto=getSetting(‘email’).replyto,
to="#rc.user_email#",
type=“html”,
subject=“Welcome #rc.user_name#!”,
server=getSetting(‘email’).server,
port=getSetting(‘email’).port,
username=getSetting(‘email’).username,
password=getSetting(‘email’).password,
priority=“3”);
// create some tokens
tokens = {contact_name=rc.firstname,user_firstname=rc.user_firstname,name=rc.user_name};
rc.mail.setBodyTokens(tokens);
// Set some body text
rc.mail.setBody(rc.emailBody);
// Send the mail
results = mailService.send(rc.mail);
}
Rather than set the body of the message within the function I store the body of the email in an external view “emails/contactRequest”. This body loads successfully and the email is deployed however the tokens do not populate.
Layout.Email looks like this:
#renderView(view=rc.emailView)#
which renders contactRequest
contactRequest.cfm looks like this:
Dear
@contact_name@
You're friend @user_name@ has sent you an invite!Okay, that email content is made up :), but it does contain the tokens that i’m trying to populate. When I receive the email the tokens display as is: @contact_name@. I ran a quick test and placed the content for setBody() within the above function as illustrated here: http://wiki.coldbox.org/wiki/WhatsNew:3.0.0.cfm#New_MailService_Plugin and was able to get the tokens to populate. It’s only when the I use an external view as the body of the email that the tokens don’t populate. Has anyone had success in populating tokens using this approach?
Thanks very much.
Nolan