Notification

I am looking for a way to send an email from RT to a specified e-mail address that is not an account in RT or associated with the ticket as a requestor, watcher, CC:, BCC:…etc…

I have the logic down to specify the e-mail address and have some nasty perl code to actually send the e-mail. But, it seems that RT has some internal module(s) that handle what the nasty perl code is doing.

I can see the RT::Action:SendEmail module, but how do I incorporate that into a script that allows me to do what I am looking to do?

Thanks,

Kurt Engle

I am looking for a way to send an email from RT to a specified e-mail address that is not an
account in RT or associated with the ticket as a requestor, watcher, CC:, BCC:…etc…

I have the logic down to specify the e-mail address and have some nasty perl code to actually
send the e-mail. But, it seems that RT has some internal module(s) that handle what the nasty
perl code is doing.

I can see the RT::Action:SendEmail module, but how do I incorporate that into a script that
allows me to do what I am looking to do?

Sounds like you actually just want to use a normal Notify action, but
have the template contain your ugly logic that sets up the To: line
based on your perl code

-kevin

That is correct. But how do I make use of the RT::Action::SendEmail module to send the notification incorporating my To: field. Or is there a better way to send out a custom notification?

Thanks for the help,

Kurt EngleFrom: “Kevin Falcone” falcone@bestpractical.com
To: rt-users@lists.bestpractical.com
Sent: Friday, December 10, 2010 8:59:25 AM
Subject: Re: [rt-users] notification

I am looking for a way to send an email from RT to a specified e-mail address that is not an
account in RT or associated with the ticket as a requestor, watcher, CC:, BCC:…etc…

I have the logic down to specify the e-mail address and have some nasty perl code to actually
send the e-mail. But, it seems that RT has some internal module(s) that handle what the nasty
perl code is doing.

I can see the RT::Action:SendEmail module, but how do I incorporate that into a script that
allows me to do what I am looking to do?

Sounds like you actually just want to use a normal Notify action, but
have the template contain your ugly logic that sets up the To: line
based on your perl code

-kevin

That is correct. But how do I make use of the RT::Action::SendEmail module to send the
notification incorporating my To: field. Or is there a better way to send out a custom
notification?

You use one of the standard Notify actions and a custom template. You
don’t write any code in the action and you don’t call the action
directly.

-kevin

Actually found a nice example of creating a template to send out an e-mail. RTFM…

However, I am having a bit of a problem constructing the To: field. Basically, I have a varialble ‘$toAddress’ that is set to an e-mail address by some prior code.

Here is my template code to construct the To: field:To: { $toAddress }
Subject: Ticket #{ $Ticket->Id()} {$Ticket->Subject()}
A new ticket has been created for you in the HelpDesk Queue.

{ $RT::WebURL } Ticket/Display.html?id={ $Ticket->Id() }

However, I keep getting ‘recipient not found’.

Kurt Engle

From: “Kevin Falcone” falcone@bestpractical.com
To: rt-users@lists.bestpractical.com
Sent: Friday, December 10, 2010 10:03:04 AM
Subject: Re: [rt-users] notification

That is correct. But how do I make use of the RT::Action::SendEmail module to send the
notification incorporating my To: field. Or is there a better way to send out a custom
notification?

You use one of the standard Notify actions and a custom template. You
don’t write any code in the action and you don’t call the action
directly.

-kevin

From: “Kevin Falcone” falcone@bestpractical.com
To: rt-users@lists.bestpractical.com
Sent: Friday, December 10, 2010 8:59:25 AM
Subject: Re: [rt-users] notification

I am looking for a way to send an email from RT to a specified e-mail address that is not
an
account in RT or associated with the ticket as a requestor, watcher, CC:, BCC:…etc…

I have the logic down to specify the e-mail address and have some nasty perl code to
actually
send the e-mail. But, it seems that RT has some internal module(s) that handle what the
nasty
perl code is doing.

I can see the RT::Action:SendEmail module, but how do I incorporate that into a script
that
allows me to do what I am looking to do?

Sounds like you actually just want to use a normal Notify action, but
have the template contain your ugly logic that sets up the To: line
based on your perl code

-kevin

Kurt,

Here’s a suggestion:

  1. Create a CustomField that will hold the “To:” Address you create from
    your scrip.
  2. Make the privileges for that CF so no one can see it or modify it (RT
    will be able to in the scrip). This way the CF does clutter up ticket
    display.
  3. Build a template to pull the value of that customField into the “To:”
    address.
  4. Create a notification scrip to use that template, action “Notify Others”
    based on your required condition.

That should work.

Kenn
LBNLOn Fri, Dec 10, 2010 at 11:07 AM, Kurt Engle engle@4j.lane.edu wrote:

Actually found a nice example of creating a template to send out an e-mail.
RTFM…

However, I am having a bit of a problem constructing the To: field.
Basically, I have a varialble ‘$toAddress’ that is set to an e-mail address
by some prior code.

Here is my template code to construct the To: field:
To: { $toAddress }
Subject: Ticket #{ $Ticket->Id()} {$Ticket->Subject()}
A new ticket has been created for you in the HelpDesk Queue.

{ $RT::WebURL } Ticket/Display.html?id={ $Ticket->Id() }

However, I keep getting ‘recipient not found’.

Kurt Engle


*From: *“Kevin Falcone” falcone@bestpractical.com
*To: *rt-users@lists.bestpractical.com
*Sent: *Friday, December 10, 2010 10:03:04 AM

*Subject: *Re: [rt-users] notification

On Fri, Dec 10, 2010 at 09:55:07AM -0800, Kurt Engle wrote:

That is correct. But how do I make use of the RT::Action::SendEmail
module to send the
notification incorporating my To: field. Or is there a better way to
send out a custom
notification?

You use one of the standard Notify actions and a custom template. You
don’t write any code in the action and you don’t call the action
directly.

-kevin

From: “Kevin Falcone” falcone@bestpractical.com
To: rt-users@lists.bestpractical.com
Sent: Friday, December 10, 2010 8:59:25 AM
Subject: Re: [rt-users] notification

On Thu, Dec 09, 2010 at 11:42:03AM -0800, Kurt Engle wrote:

I am looking for a way to send an email from RT to a specified
e-mail address that is not
an
account in RT or associated with the ticket as a requestor,
watcher, CC:, BCC:…etc…

I have the logic down to specify the e-mail address and have some
nasty perl code to
actually
send the e-mail. But, it seems that RT has some internal
module(s) that handle what the
nasty
perl code is doing.

I can see the RT::Action:SendEmail module, but how do I
incorporate that into a script
that
allows me to do what I am looking to do?

Sounds like you actually just want to use a normal Notify action, but
have the template contain your ugly logic that sets up the To: line
based on your perl code

-kevin

Actually found a nice example of creating a template to send out an e-mail. RTFM…

However, I am having a bit of a problem constructing the To: field. Basically, I have a
varialble ‘$toAddress’ that is set to an e-mail address by some prior code.

Where in the code is it set. It would really need to be in that
template

Here is my template code to construct the To: field:
To: { $toAddress }
Subject: Ticket #{ $Ticket->Id()} {$Ticket->Subject()}
A new ticket has been created for you in the HelpDesk Queue.

{ $RT::WebURL } Ticket/Display.html?id={ $Ticket->Id() }

However, I keep getting ‘recipient not found’.

In debug logging mode, RT will actually dump copies of the email being
processed into the logs, which would show you the To:

Please note that if To: is your email address and you’re the actor on
this ticket while testing, you may have told RT not to send you email
in that case using $NotifyActor

-kevin

Kevin,

The template would look like this:

A scrip based on whatever condition would do this:

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = new RT::CustomField($RT::SystemUser);
my $cf_name = “ToOverride”;

if condition is “A”
$my $cf_value = “the To address you want for “A” condition”;
elsif condition is “B”
$my $cf_value = “the To address you want for “B” condition”;

and on and on till you’re thru.

then, set the Custom Field as the last piece of action code:

$cf_obj->LoadByName(Name=>$cf_name);
$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n” );
$ticket->AddCustomFieldValue( Field=>$cf_obj, Value=>$cf_value,
RecordTransaction=>0 );

return 1;

Then write a notification scrip to use the new template based on your
conditions.
Use “TransactioBatch” for both scrips.

Hope this helps.

Kenn
LBNLOn Fri, Dec 10, 2010 at 11:55 AM, Kevin Falcone falcone@bestpractical.comwrote:

On Fri, Dec 10, 2010 at 11:07:32AM -0800, Kurt Engle wrote:

Actually found a nice example of creating a template to send out an
e-mail. RTFM…

However, I am having a bit of a problem constructing the To: field.
Basically, I have a
varialble ‘$toAddress’ that is set to an e-mail address by some prior
code.

Where in the code is it set. It would really need to be in that
template

Here is my template code to construct the To: field:
To: { $toAddress }
Subject: Ticket #{ $Ticket->Id()} {$Ticket->Subject()}
A new ticket has been created for you in the HelpDesk Queue.

{ $RT::WebURL } Ticket/Display.html?id={ $Ticket->Id() }

However, I keep getting ‘recipient not found’.

In debug logging mode, RT will actually dump copies of the email being
processed into the logs, which would show you the To:

Please note that if To: is your email address and you’re the actor on
this ticket while testing, you may have told RT not to send you email
in that case using $NotifyActor

-kevin


From: “Kevin Falcone” falcone@bestpractical.com
To: rt-users@lists.bestpractical.com
Sent: Friday, December 10, 2010 10:03:04 AM
Subject: Re: [rt-users] notification

On Fri, Dec 10, 2010 at 09:55:07AM -0800, Kurt Engle wrote:

That is correct. But how do I make use of the
RT::Action::SendEmail module to send the
notification incorporating my To: field. Or is there a better way
to send out a custom
notification?

You use one of the standard Notify actions and a custom template. You
don’t write any code in the action and you don’t call the action
directly.

-kevin

From: “Kevin Falcone” falcone@bestpractical.com
To: rt-users@lists.bestpractical.com
Sent: Friday, December 10, 2010 8:59:25 AM
Subject: Re: [rt-users] notification

On Thu, Dec 09, 2010 at 11:42:03AM -0800, Kurt Engle wrote:

I am looking for a way to send an email from RT to a
specified e-mail address that
is not
an
account in RT or associated with the ticket as a requestor,
watcher, CC:,
BCC:…etc…

I have the logic down to specify the e-mail address and have
some nasty perl code to
actually
send the e-mail. But, it seems that RT has some internal
module(s) that handle what
the
nasty
perl code is doing.

I can see the RT::Action:SendEmail module, but how do I
incorporate that into a
script
that
allows me to do what I am looking to do?

Sounds like you actually just want to use a normal Notify action,
but
have the template contain your ugly logic that sets up the To:
line
based on your perl code

-kevin

Kevin,
The template would look like this:

Kenn

I’m perfectly able to write the scrip and template in question, but
since Kurt has a half-working template I was curious what he was
doing. Involving a CustomField seems like a bit of overkill.

-kevin

Kevin,

OPPS! Sorry, man. I got confused. I certainly didn’t mean to disrespect you.

KennOn Fri, Dec 10, 2010 at 12:23 PM, Kevin Falcone falcone@bestpractical.comwrote:

On Fri, Dec 10, 2010 at 12:08:05PM -0800, Kenneth Crocker wrote:

Kevin,
The template would look like this:

Kenn

I’m perfectly able to write the scrip and template in question, but
since Kurt has a half-working template I was curious what he was
doing. Involving a CustomField seems like a bit of overkill.

-kevin

To: {$Ticket->FirstCustomFieldValue(‘ToOverride’)}@[1]lbl.gov
Subject: Request Titled: “{$Ticket->Subject}” is ready to Migrate!

A scrip based on whatever condition would do this:

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = new RT::CustomField($RT::SystemUser);
my $cf_name = “ToOverride”;

if condition is “A”
$my $cf_value = “the To address you want for “A” condition”;
elsif condition is “B”
$my $cf_value = “the To address you want for “B” condition”;

and on and on till you’re thru.

then, set the Custom Field as the last piece of action code:

$cf_obj->LoadByName(Name=>$cf_name);
$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n” );
$ticket->AddCustomFieldValue( Field=>$cf_obj, Value=>$cf_value,
RecordTransaction=>0 );

return 1;

Then write a notification scrip to use the new template based on your
conditions.
Use “TransactioBatch” for both scrips.

Hope this helps.

Kenn
LBNL

On Fri, Dec 10, 2010 at 11:55 AM, Kevin Falcone <[2] falcone@bestpractical.com> wrote:

 On Fri, Dec 10, 2010 at 11:07:32AM -0800, Kurt Engle wrote:
 > Actually found a nice example of creating a template to send out

an e-mail. RTFM…

 >
 > However, I am having a bit of a problem constructing the To:

field. Basically, I have a

 > varialble '$toAddress' that is set to an e-mail address by some

prior code.

 Where in the code is it set. It would really need to be in that
 template
 > Here is my template code to construct the To: field:
 > To: { $toAddress }
 > Subject: Ticket #{ $Ticket->Id()} {$Ticket->Subject()}
 > A new ticket has been created for you in the HelpDesk Queue.
 >
 > { $RT::WebURL } Ticket/Display.html?id={ $Ticket->Id() }
 >
 > However, I keep getting 'recipient not found'.

 In debug logging mode, RT will actually dump copies of the email

being

 processed into the logs, which would show you the To:

 Please note that if To: is your email address and you're the actor

on

 this ticket while testing, you may have told RT not to send you

email

 in that case using $NotifyActor
 -kevin

 >

 >
 > From: "Kevin Falcone" <[3]falcone@bestpractical.com>
 > To: [4]rt-users@lists.bestpractical.com
 > Sent: Friday, December 10, 2010 10:03:04 AM
 > Subject: Re: [rt-users] notification
 >
 > On Fri, Dec 10, 2010 at 09:55:07AM -0800, Kurt Engle wrote:
 > > That is correct. But how do I make use of the

RT::Action::SendEmail module to send the

 > > notification incorporating my To: field. Or is there a better

way to send out a custom

 > > notification?
 >
 > You use one of the standard Notify actions and a custom template.

You

 > don't write any code in the action and you don't call the action
 > directly.
 >
 > -kevin
 >
 > > From: "Kevin Falcone" <[5]falcone@bestpractical.com>
 > > To: [6]rt-users@lists.bestpractical.com
 > > Sent: Friday, December 10, 2010 8:59:25 AM
 > > Subject: Re: [rt-users] notification
 > >
 > > On Thu, Dec 09, 2010 at 11:42:03AM -0800, Kurt Engle wrote:
 > > > I am looking for a way to send an email from RT to a specified

e-mail address that

 > is not
 > > an
 > > > account in RT or associated with the ticket as a requestor,

watcher, CC:,

 > BCC:...etc....
 > > >
 > > > I have the logic down to specify the e-mail address and have

some nasty perl code to

 > > actually
 > > > send the e-mail. But, it seems that RT has some internal

module(s) that handle what

 > the
 > > nasty
 > > > perl code is doing.
 > > >
 > > > I can see the RT::Action:SendEmail module, but how do I

incorporate that into a

 > script
 > > that
 > > > allows me to do what I am looking to do?
 > >
 > > Sounds like you actually just want to use a normal Notify

action, but

 > > have the template contain your ugly logic that sets up the To:

line

 > > based on your perl code
 > >
 > > -kevin

References

Visible links

  1. http://lbl.gov/
  2. mailto:falcone@bestpractical.com
  3. mailto:falcone@bestpractical.com
  4. mailto:rt-users@lists.bestpractical.com
  5. mailto:falcone@bestpractical.com
  6. mailto:rt-users@lists.bestpractical.com

So here is the code that I am working with inside my template:
Script:
Condition: On Create
Action: Notify Other Recipients
Template: My Notify
Stage: TransactionBatch

‘My Notify’ code
{
my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf = new RT::CustomField($RT::SystemUser);
$cf->LoadByName(Queue => $ticket->QueueObj->id,Name => “Building”);
return 0 unless $cf->id;
my $cfvalue = $ticket->FirstCustomFieldValue(‘Building’);

my $to_address = “”;

if ($cfvalue =~ /Sheldon/) {
$to_address = “sheldonhd”;
}
elsif ($cfvalue =~ /North/) {
$to_address = “northhd”;
}
elsif ($cfvalue =~ /South/) {
$to_address = “southhd”;
}
elsif ($cfvalue =~ /Churchill/) {
$to_address = “churchillhd”;
}
elsif ($cfvalue =~ /Kennedy/) {
$to_address = “kennedyhd”;
}
elsif ($cfvalue =~ /Kelly/) {
$to_address = “kellyhd”;
}
elsif ($cfvalue =~ /Computer/) {
$to_address = “engle”;
else {
$to_address= “rubble”;
}
return 1;
}To: {$to_address}@4j.lane.edu"}
Subject: New Ticket #{ $Ticket->Id() } has been created

Time to go to work

In my debug log, I am not even seeing the script being called that contains this template. If I strip everything above the ‘To:’ field, the scrip and template gets called but the e-mail is not sent even when I hard code the e-mail address.

Kurt Engle

From: “Kevin Falcone” falcone@bestpractical.com
To: rt-users@lists.bestpractical.com
Sent: Friday, December 10, 2010 12:23:28 PM
Subject: Re: [rt-users] notification

Kevin,
The template would look like this:

Kenn

I’m perfectly able to write the scrip and template in question, but
since Kurt has a half-working template I was curious what he was
doing. Involving a CustomField seems like a bit of overkill.

-kevin

To: {$Ticket->FirstCustomFieldValue(‘ToOverride’)}@[1]lbl.gov
Subject: Request Titled: “{$Ticket->Subject}” is ready to Migrate!

A scrip based on whatever condition would do this:

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = new RT::CustomField($RT::SystemUser);
my $cf_name = “ToOverride”;

if condition is “A”
$my $cf_value = “the To address you want for “A” condition”;
elsif condition is “B”
$my $cf_value = “the To address you want for “B” condition”;

and on and on till you’re thru.

then, set the Custom Field as the last piece of action code:

$cf_obj->LoadByName(Name=>$cf_name);
$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n” );
$ticket->AddCustomFieldValue( Field=>$cf_obj, Value=>$cf_value, RecordTransaction=>0 );

return 1;

Then write a notification scrip to use the new template based on your conditions.
Use “TransactioBatch” for both scrips.

Hope this helps.

Kenn
LBNL

Actually found a nice example of creating a template to send out an e-mail. RTFM…

However, I am having a bit of a problem constructing the To: field. Basically, I have a
varialble ‘$toAddress’ that is set to an e-mail address by some prior code.

Where in the code is it set. It would really need to be in that
template

Here is my template code to construct the To: field:
To: { $toAddress }
Subject: Ticket #{ $Ticket->Id()} {$Ticket->Subject()}
A new ticket has been created for you in the HelpDesk Queue.

{ $RT::WebURL } Ticket/Display.html?id={ $Ticket->Id() }

However, I keep getting ‘recipient not found’.

In debug logging mode, RT will actually dump copies of the email being
processed into the logs, which would show you the To:

Please note that if To: is your email address and you’re the actor on
this ticket while testing, you may have told RT not to send you email
in that case using $NotifyActor
-kevin


From: “Kevin Falcone” <[3]falcone@bestpractical.com>
To: [4]rt-users@lists.bestpractical.com
Sent: Friday, December 10, 2010 10:03:04 AM
Subject: Re: [rt-users] notification

That is correct. But how do I make use of the RT::Action::SendEmail module to send the
notification incorporating my To: field. Or is there a better way to send out a custom
notification?

You use one of the standard Notify actions and a custom template. You
don’t write any code in the action and you don’t call the action
directly.

-kevin

From: “Kevin Falcone” <[5]falcone@bestpractical.com>
To: [6]rt-users@lists.bestpractical.com
Sent: Friday, December 10, 2010 8:59:25 AM
Subject: Re: [rt-users] notification

I am looking for a way to send an email from RT to a specified e-mail address that
is not
an
account in RT or associated with the ticket as a requestor, watcher, CC:,
BCC:…etc…

I have the logic down to specify the e-mail address and have some nasty perl code to
actually
send the e-mail. But, it seems that RT has some internal module(s) that handle what
the
nasty
perl code is doing.

I can see the RT::Action:SendEmail module, but how do I incorporate that into a
script
that
allows me to do what I am looking to do?

Sounds like you actually just want to use a normal Notify action, but
have the template contain your ugly logic that sets up the To: line
based on your perl code

-kevin

References

Visible links

  1. http://lbl.gov/
  2. mailto:falcone@bestpractical.com
  3. mailto:falcone@bestpractical.com
  4. mailto:rt-users@lists.bestpractical.com
  5. mailto:falcone@bestpractical.com
  6. mailto:rt-users@lists.bestpractical.com

I have removed the blank lines, thank you for that tip. I am sending in the ‘ticket’ as a user other than myself and I am trying to notify someone other than myself. I am still not seeing the scrip being run.

But, if I put the following code in the template:
{my $to_address = “username” }To: {$to_address}@4j.lane.edu
Subject: New Ticket #{ $Ticket->Id() } has been created

Time to go to work

The script that uses this template gets run but I get an error on the recipients. I am trying to create a simple test that will successfully sendout e-mail, then I can start trying to figure out why my code is broken.

Kurt Engle

From: “Kevin Falcone” falcone@bestpractical.com
To: “Kurt Engle” engle@4j.lane.edu
Sent: Monday, December 13, 2010 11:34:58 AM
Subject: Re: [rt-users] notification

So here is the code that I am working with inside my template:
}

To: {$to_address}@4j.lane.edu"}
Subject: New Ticket #{ $Ticket->Id() } has been created

Time to go to work

In my debug log, I am not even seeing the script being called that
contains this template. If I strip everything above the ‘To:’ field,
the scrip and template gets called but the e-mail is not sent even
when I hard code the e-mail address.

You can’t have blank lines above To:

Headers need to be the first lines in the template (after your code)
Having blank lines like that means that the To: is going in the body

Also, I believe we asked about NotifyActor. If you’re testing as
yourself and emailing yourself RT will not notify you based on the
setting of that variable

-kevin

I have removed the blank lines, thank you for that tip. I am sending in the ‘ticket’ as a user
other than myself and I am trying to notify someone other than myself. I am still not seeing
the scrip being run.

But, if I put the following code in the template:

{my $to_address = “username” }
To: {$to_address}@4j.lane.edu
Subject: New Ticket #{ $Ticket->Id() } has been created

Time to go to work

The script that uses this template gets run but I get an error on the recipients. I am trying
to create a simple test that will successfully sendout e-mail, then I can start trying to
figure out why my code is broken.

Please include the error

Kurt,

Not sure why you start the scrip with a “{” and end with one. Just start
with the “my $trans=”.

Your code should be in the “Prep Action” and you should add this at the end
of the code you’ve got:

else {
$to_address= “rubble”;

after the above line, the code should look like this:

copy value of “To_Address” to Custom Field “Whatever you named it”

my $cf_name = “Whatever it is”;

$cf_obj->LoadByName( Name => $cf_name );
$RT::Logger->debug( “Loaded $cf_obj->Name = “. $cf_obj->Name() .”\n” );
$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$to_address,
RecordTransaction=>0);

return 1;

Then make sure the “Cleanup Action” ends with a “return 1;” or the scrip
doesn’t finish.
Also, not sure why you start the scrip with a “{” and end with one. Just
start with the “my $trans=”.

The Template should refer to the value in the CF you created for the “To
Address”, like this:

whatever

That should do it.

Kenn
LBNLOn Mon, Dec 13, 2010 at 11:15 AM, Kurt Engle engle@4j.lane.edu wrote:

So here is the code that I am working with inside my template:
Script:
Condition: On Create
Action: Notify Other Recipients
Template: My Notify
Stage: TransactionBatch

‘My Notify’ code

{
my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf = new RT::CustomField($RT::SystemUser);
$cf->LoadByName(Queue => $ticket->QueueObj->id,Name => “Building”);
return 0 unless $cf->id;
my $cfvalue = $ticket->FirstCustomFieldValue(‘Building’);

my $to_address = “”;

if ($cfvalue =~ /Sheldon/) {
$to_address = “sheldonhd”;
}
elsif ($cfvalue =~ /North/) {
$to_address = “northhd”;
}
elsif ($cfvalue =~ /South/) {
$to_address = “southhd”;
}
elsif ($cfvalue =~ /Churchill/) {
$to_address = “churchillhd”;
}
elsif ($cfvalue =~ /Kennedy/) {
$to_address = “kennedyhd”;
}
elsif ($cfvalue =~ /Kelly/) {
$to_address = “kellyhd”;
}
elsif ($cfvalue =~ /Computer/) {
$to_address = “engle”;
else {
$to_address= “rubble”;
}
return 1;
}

To: {$to_address}@4j.lane.edu to_address}@4j.lane.edu"}
Subject: New Ticket #{ $Ticket->Id() } has been created

Time to go to work

In my debug log, I am not even seeing the script being called that contains
this template. If I strip everything above the ‘To:’ field, the scrip and
template gets called but the e-mail is not sent even when I hard code the
e-mail address.

Kurt Engle


*From: *“Kevin Falcone” falcone@bestpractical.com
*To: *rt-users@lists.bestpractical.com
*Sent: *Friday, December 10, 2010 12:23:28 PM
*Subject: *Re: [rt-users] notification

On Fri, Dec 10, 2010 at 12:08:05PM -0800, Kenneth Crocker wrote:

Kevin,
The template would look like this:

Kenn

I’m perfectly able to write the scrip and template in question, but
since Kurt has a half-working template I was curious what he was
doing. Involving a CustomField seems like a bit of overkill.

-kevin

To: {$Ticket->FirstCustomFieldValue(‘ToOverride’)}@[1]lbl.gov
Subject: Request Titled: “{$Ticket->Subject}” is ready to Migrate!

A scrip based on whatever condition would do this:

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = new RT::CustomField($RT::SystemUser);
my $cf_name = “ToOverride”;

if condition is “A”
$my $cf_value = “the To address you want for “A” condition”;
elsif condition is “B”
$my $cf_value = “the To address you want for “B” condition”;

and on and on till you’re thru.

then, set the Custom Field as the last piece of action code:

$cf_obj->LoadByName(Name=>$cf_name);
$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n” );
$ticket->AddCustomFieldValue( Field=>$cf_obj, Value=>$cf_value,
RecordTransaction=>0 );

return 1;

Then write a notification scrip to use the new template based on your
conditions.
Use “TransactioBatch” for both scrips.

Hope this helps.

Kenn
LBNL

On Fri, Dec 10, 2010 at 11:55 AM, Kevin Falcone <[2] falcone@bestpractical.com> wrote:

 On Fri, Dec 10, 2010 at 11:07:32AM -0800, Kurt Engle wrote:
 > Actually found a nice example of creating a template to send out

an e-mail. RTFM…

 >
 > However, I am having a bit of a problem constructing the To:

field. Basically, I have a

 > varialble '$toAddress' that is set to an e-mail address by some

prior code.

 Where in the code is it set. It would really need to be in that
 template
 > Here is my template code to construct the To: field:
 > To: { $toAddress }
 > Subject: Ticket #{ $Ticket->Id()} {$Ticket->Subject()}
 > A new ticket has been created for you in the HelpDesk Queue.
 >
 > { $RT::WebURL } Ticket/Display.html?id={ $Ticket->Id() }
 >
 > However, I keep getting 'recipient not found'.

 In debug logging mode, RT will actually dump copies of the email

being

 processed into the logs, which would show you the To:

 Please note that if To: is your email address and you're the actor

on

 this ticket while testing, you may have told RT not to send you

email

 in that case using $NotifyActor
 -kevin

 >

 >
 > From: "Kevin Falcone" <[3]falcone@bestpractical.com>
 > To: [4]rt-users@lists.bestpractical.com
 > Sent: Friday, December 10, 2010 10:03:04 AM
 > Subject: Re: [rt-users] notification
 >
 > On Fri, Dec 10, 2010 at 09:55:07AM -0800, Kurt Engle wrote:
 > > That is correct. But how do I make use of the

RT::Action::SendEmail module to send the

 > > notification incorporating my To: field. Or is there a better

way to send out a custom

 > > notification?
 >
 > You use one of the standard Notify actions and a custom template.

You

 > don't write any code in the action and you don't call the action
 > directly.
 >
 > -kevin
 >
 > > From: "Kevin Falcone" <[5]falcone@bestpractical.com>
 > > To: [6]rt-users@lists.bestpractical.com
 > > Sent: Friday, December 10, 2010 8:59:25 AM
 > > Subject: Re: [rt-users] notification
 > >
 > > On Thu, Dec 09, 2010 at 11:42:03AM -0800, Kurt Engle wrote:
 > > > I am looking for a way to send an email from RT to a specified

e-mail address that

 > is not
 > > an
 > > > account in RT or associated with the ticket as a requestor,

watcher, CC:,

 > BCC:...etc....
 > > >
 > > > I have the logic down to specify the e-mail address and have

some nasty perl code to

 > > actually
 > > > send the e-mail. But, it seems that RT has some internal

module(s) that handle what

 > the
 > > nasty
 > > > perl code is doing.
 > > >
 > > > I can see the RT::Action:SendEmail module, but how do I

incorporate that into a

 > script
 > > that
 > > > allows me to do what I am looking to do?
 > >
 > > Sounds like you actually just want to use a normal Notify

action, but

 > > have the template contain your ugly logic that sets up the To:

line

 > > based on your perl code
 > >
 > > -kevin

References

Visible links

  1. http://lbl.gov/
  2. mailto:falcone@bestpractical.com
  3. mailto:falcone@bestpractical.com
  4. mailto:rt-users@lists.bestpractical.com
  5. mailto:falcone@bestpractical.com
  6. mailto:rt-users@lists.bestpractical.com

This code was entered in a template not a script. I was trying Kevin’s suggestion with doing it all in one go. I figure that if I can capture the CustomField in the template code and test on that value to return my $to_address, then I am pretty much set to create my outgoing e-mail at the same time.

Kurt Engle
Network Engineer
Eugene 4J SchoolsFrom: “Kenneth Crocker” kfcrocker@lbl.gov
To: rt-users@lists.bestpractical.com
Sent: Monday, December 13, 2010 12:12:50 PM
Subject: Re: [rt-users] notification

Kurt,

Not sure why you start the scrip with a “{” and end with one. Just start with the “my $trans=”.

Your code should be in the “Prep Action” and you should add this at the end of the code you’ve got:

else {
$to_address= “rubble”;

after the above line, the code should look like this:

copy value of “To_Address” to Custom Field “Whatever you named it”

my $cf_name = “Whatever it is”;

$cf_obj->LoadByName( Name => $cf_name );
$RT::Logger->debug( “Loaded $cf_obj->Name = “. $cf_obj->Name() .”\n” );
$ticket->AddCustomFieldValue(Field=>$cf_obj, Value=>$to_address, RecordTransaction=>0);

return 1;

Then make sure the “Cleanup Action” ends with a “return 1;” or the scrip doesn’t finish.
Also, not sure why you start the scrip with a “{” and end with one. Just start with the “my $trans=”.

The Template should refer to the value in the CF you created for the “To Address”, like this:

To: {$Ticket->FirstCustomFieldValue(‘To Address Value’)}@ 4j.lane.edu
Subject: Request Titled: “{$Ticket->Subject}” is ready to Migrate or whatever

That should do it.

Kenn
LBNL

So here is the code that I am working with inside my template:
Script:
Condition: On Create
Action: Notify Other Recipients
Template: My Notify
Stage: TransactionBatch

‘My Notify’ code
{
my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf = new RT::CustomField($RT::SystemUser);
$cf->LoadByName(Queue => $ticket->QueueObj->id,Name => “Building”);
return 0 unless $cf->id;
my $cfvalue = $ticket->FirstCustomFieldValue(‘Building’);

my $to_address = “”;

if ($cfvalue =~ /Sheldon/) {
$to_address = “sheldonhd”;
}
elsif ($cfvalue =~ /North/) {
$to_address = “northhd”;
}
elsif ($cfvalue =~ /South/) {
$to_address = “southhd”;
}
elsif ($cfvalue =~ /Churchill/) {
$to_address = “churchillhd”;
}
elsif ($cfvalue =~ /Kennedy/) {
$to_address = “kennedyhd”;
}
elsif ($cfvalue =~ /Kelly/) {
$to_address = “kellyhd”;
}
elsif ($cfvalue =~ /Computer/) {
$to_address = “engle”;
else {
$to_address= “rubble”;
}
return 1;
}

To: {$ to_address}@4j.lane.edu "}
Subject: New Ticket #{ $Ticket->Id() } has been created

Time to go to work

In my debug log, I am not even seeing the script being called that contains this template. If I strip everything above the ‘To:’ field, the scrip and template gets called but the e-mail is not sent even when I hard code the e-mail address.

Kurt Engle

From: “Kevin Falcone” < falcone@bestpractical.com >
To: rt-users@lists.bestpractical.com
Sent: Friday, December 10, 2010 12:23:28 PM
Subject: Re: [rt-users] notification

Kevin,
The template would look like this:

Kenn

I’m perfectly able to write the scrip and template in question, but
since Kurt has a half-working template I was curious what he was
doing. Involving a CustomField seems like a bit of overkill.

-kevin

To: {$Ticket->FirstCustomFieldValue(‘ToOverride’)}@[1] lbl.gov
Subject: Request Titled: “{$Ticket->Subject}” is ready to Migrate!

A scrip based on whatever condition would do this:

my $trans = $self->TransactionObj;
my $ticket = $self->TicketObj;
my $cf_obj = new RT::CustomField($RT::SystemUser);
my $cf_name = “ToOverride”;

if condition is “A”
$my $cf_value = “the To address you want for “A” condition”;
elsif condition is “B”
$my $cf_value = “the To address you want for “B” condition”;

and on and on till you’re thru.

then, set the Custom Field as the last piece of action code:

$cf_obj->LoadByName(Name=>$cf_name);
$RT::Logger->debug(“Loaded$cf_obj->Name = “. $cf_obj->Name() .”\n” );
$ticket->AddCustomFieldValue( Field=>$cf_obj, Value=>$cf_value, RecordTransaction=>0 );

return 1;

Then write a notification scrip to use the new template based on your conditions.
Use “TransactioBatch” for both scrips.

Hope this helps.

Kenn
LBNL

Actually found a nice example of creating a template to send out an e-mail. RTFM…

However, I am having a bit of a problem constructing the To: field. Basically, I have a
varialble ‘$toAddress’ that is set to an e-mail address by some prior code.

Where in the code is it set. It would really need to be in that
template

Here is my template code to construct the To: field:
To: { $toAddress }
Subject: Ticket #{ $Ticket->Id()} {$Ticket->Subject()}
A new ticket has been created for you in the HelpDesk Queue.

{ $RT::WebURL } Ticket/Display.html?id={ $Ticket->Id() }

However, I keep getting ‘recipient not found’.

In debug logging mode, RT will actually dump copies of the email being
processed into the logs, which would show you the To:

Please note that if To: is your email address and you’re the actor on
this ticket while testing, you may have told RT not to send you email
in that case using $NotifyActor
-kevin


From: “Kevin Falcone” <[3] falcone@bestpractical.com >
To: [4] rt-users@lists.bestpractical.com
Sent: Friday, December 10, 2010 10:03:04 AM
Subject: Re: [rt-users] notification

That is correct. But how do I make use of the RT::Action::SendEmail module to send the
notification incorporating my To: field. Or is there a better way to send out a custom
notification?

You use one of the standard Notify actions and a custom template. You
don’t write any code in the action and you don’t call the action
directly.

-kevin

From: “Kevin Falcone” <[5] falcone@bestpractical.com >
To: [6] rt-users@lists.bestpractical.com
Sent: Friday, December 10, 2010 8:59:25 AM
Subject: Re: [rt-users] notification

I am looking for a way to send an email from RT to a specified e-mail address that
is not
an
account in RT or associated with the ticket as a requestor, watcher, CC:,
BCC:…etc…

I have the logic down to specify the e-mail address and have some nasty perl code to
actually
send the e-mail. But, it seems that RT has some internal module(s) that handle what
the
nasty
perl code is doing.

I can see the RT::Action:SendEmail module, but how do I incorporate that into a
script
that
allows me to do what I am looking to do?

Sounds like you actually just want to use a normal Notify action, but
have the template contain your ugly logic that sets up the To: line
based on your perl code

-kevin

References

Visible links

  1. http://lbl.gov/
  2. mailto: falcone@bestpractical.com
  3. mailto: falcone@bestpractical.com
  4. mailto: rt-users@lists.bestpractical.com
  5. mailto: falcone@bestpractical.com
  6. mailto: rt-users@lists.bestpractical.com

The error that I am getting is:

[Mon Dec 13 22:05:45 2010] [info]: rt-3.8.8-18199-1292277945-1004.587-26-0@4j.lane.edu #587/7702 - Scrip 26 Email TSS from Template (/opt/rt3/bin/…/lib/RT/Action/SendEmail.pm:300)
[Mon Dec 13 22:05:45 2010] [info]: rt-3.8.8-18199-1292277945-1004.587-26-0@4j.lane.edu No recipients found. Not sending. (/opt/rt3/bin/…/lib/RT/Interface/Email.pm:352)

Here are the details for scrip #26:
Condition: On Create
Action: Notify Other Recipients
Template: My Notify
Stage: TransactionBatch

The code that generated this error in my template is:
{ my $to_address = “rubble”; }To: {$to_address}@4j.lane.edu
Subject: New Ticket #{ $Ticket->Id() } has been created

Time to go to work

I really appreciate your help with this. Once I get this solved, RT will provide some much needed customization for our environment.

Thanks,

Kurt Engle

From: “Kevin Falcone” falcone@bestpractical.com
To: rt-users@lists.bestpractical.com
Sent: Monday, December 13, 2010 12:11:12 PM
Subject: Re: [rt-users] notification

I have removed the blank lines, thank you for that tip. I am sending in the ‘ticket’ as a user
other than myself and I am trying to notify someone other than myself. I am still not seeing
the scrip being run.

But, if I put the following code in the template:

{my $to_address = “username” }
To: {$to_address}@4j.lane.edu
Subject: New Ticket #{ $Ticket->Id() } has been created

Time to go to work

The script that uses this template gets run but I get an error on the recipients. I am trying
to create a simple test that will successfully sendout e-mail, then I can start trying to
figure out why my code is broken.

Please include the error

Action: Notify Other Recipients

Oh, I wonder if that is your problem. Notify Other Recipients
notifies CCs

{ my $to_address = “rubble”; }
To: {$to_address}@4j.lane.edu
Subject: New Ticket #{ $Ticket->Id() } has been created

What happens if you Cc: to that address, or RT-Send-Cc: to that
address?

-kevin

I am trying to approach this a little differently now. I am skipping the email part, and just trying to get it to print the value I want in the email (I am hard coding the To: field)

But when I use this in the body of the email: { $Ticket->CustomFieldValues(‘NotifyEmail’);}

My result is this: RT::ObjectCustomFieldValues=HASH(0x2b9a63a9c110)

But I cannot figure out how to get the value out of the Hash.

Kurt Engle
Network Engineer
Eugene 4J SchoolsFrom: “Kevin Falcone” falcone@bestpractical.com
To: rt-users@lists.bestpractical.com
Sent: Tuesday, December 14, 2010 8:19:16 AM
Subject: Re: [rt-users] notification

Action: Notify Other Recipients

Oh, I wonder if that is your problem. Notify Other Recipients
notifies CCs

{ my $to_address = “rubble”; }
To: {$to_address}@4j.lane.edu
Subject: New Ticket #{ $Ticket->Id() } has been created

What happens if you Cc: to that address, or RT-Send-Cc: to that
address?

-kevin

I am trying to approach this a little differently now. I am skipping the email part, and just
trying to get it to print the value I want in the email (I am hard coding the To: field)

But when I use this in the body of the email: { $Ticket->CustomFieldValues(‘NotifyEmail’);}

My result is this: RT::ObjectCustomFieldValues=HASH(0x2b9a63a9c110)
But I cannot figure out how to get the value out of the Hash.

You’re missing the word First in your method call

-kevin

I have tried FirstCustomFieldValue(‘NotifyEmail’) but it returns nothing. But I can look at the ticket and it shows the value that I would expect there.

FirstCustomFieldValues(‘NotifyEmail’) returns this in the log file:
Template parsing error: RT::ticket::FirstCustomFieldValues Unimplemented in Text::Template::GEN14.

Kurt Engle
Network Engineer
Eugene 4J SchoolsFrom: “Kevin Falcone” falcone@bestpractical.com
To: rt-users@lists.bestpractical.com
Sent: Tuesday, December 14, 2010 10:40:33 AM
Subject: Re: [rt-users] notification

I am trying to approach this a little differently now. I am skipping the email part, and just
trying to get it to print the value I want in the email (I am hard coding the To: field)

But when I use this in the body of the email: { $Ticket->CustomFieldValues(‘NotifyEmail’);}

My result is this: RT::ObjectCustomFieldValues=HASH(0x2b9a63a9c110)
But I cannot figure out how to get the value out of the Hash.

You’re missing the word First in your method call

-kevin


From: “Kevin Falcone” falcone@bestpractical.com
To: rt-users@lists.bestpractical.com
Sent: Tuesday, December 14, 2010 8:19:16 AM
Subject: Re: [rt-users] notification

Action: Notify Other Recipients

Oh, I wonder if that is your problem. Notify Other Recipients
notifies CCs

{ my $to_address = “rubble”; }
To: {$to_address}@4j.lane.edu
Subject: New Ticket #{ $Ticket->Id() } has been created

What happens if you Cc: to that address, or RT-Send-Cc: to that
address?

-kevin