Interceptors, MailService - access to RC

Hi folks,

I’m not sure if my subject line is correct, but here is my issue.

In my handler I announce an interception. My interception point performs some checks and then calls another function in the interceptor, passing data from the checks.

function dispatchEmail(user,partner,contact,group){

log.debug("--------start dispatch email-----------");

//set email view
rc.emailView = “emails/testsend”;
//set email layout based on partnerid
rc.emailBody = getPlugin(“Renderer”).renderLayout("#partner.getPartnerKey()#/Layout.#partner.getPartnerKey()#.Email");
//Get new mail object
rc.mail = mailService.newMail().config(from="#arguments.user.getName()# via #getSetting(‘email’).from#",
replyto=getSetting(‘email’).replyto,
to="#arguments.contact.getEmail()#",
type=“html”,
subject=“Test email send”,
server=getSetting(‘email’).server,
port=getSetting(‘email’).port,
username=getSetting(‘email’).username,
password=getSetting(‘email’).password,
priority=“5”);

//create email tokens
rc.tokens = {contact_name=arguments.contact.getName(),
contact_firstname=arguments.contact.getFirstName(),
user_firstname=arguments.user.getFirstName(),
user_name=arguments.user.getName(),
contact_email=arguments.contact.getEmail()};

//set email tokens
rc.mail.setBodyTokens(rc.tokens);
//set body of email
rc.mail.setBody(rc.emailBody);

// Send the mail
results = mailService.send(rc.mail);
log.debug("--------end dispatch email-----------");

}

When renderLayount tries to execute I get an error saying that rc.emailView is undefined. I’m guess this is the case because dispatchEmail doesn’t have access to the request collection, and emailView hasn’t been appended. In order to fix this would I just pass the event argument of my interception point to the dispatchEmail function or is there another way I can get access to rc from within dispatchEmail and append email view?

Thanks.

Nolan

You have all these RC variables set in that function but no RC scope defined?

Yes. That's what i'm wondering how to do.

My interception point is calling a function inline to the interceptor component. do I need to pass pass the rc variable to the inline function or can I get a reference to rc another way from within the dispatchEmail() function. I tried passing the event/rc like so, but I'm not sure if was the right approach...

dispatchEmail(arguments.event,mydata) with arguments.event being the event passed into the interception point..

does that make sense or did I just confuse things :wink:

Thanks.

Nolan

Nolan,

The interception point receives the event, so if you want to call inline functions within your interceptor, you will have to pass the event along with it so you can have access to it.

Nothing unusual there.

Thanks Luis,

I was able to get it to work. Cheers,

Nolan