Possible to get the "To:" header in a template?

I’d like to add some conditional logic to a template based on what address the customer emailed. Is this possible?

I haven’t test it but you can try

my $user = RT::User->new( $ticket->Creator );
my $email = $user->EmailAddress;

If this is a template run by a scrip doing an “On Correspond” condition, you should find that there is a $Transaction variable available. This is an RT::Transaction object, so you can call the Addresses() method on it to get a hashref of all addresses related to this transaction (attachment). The keys of the hash are From, To, Cc, Bcc, RT-Send-Cc and RT-Send-Bcc. The values are references to lists of Email::Address objects.

So you might be able to use something like this:

my $addresses = $Transaction->Addresses();
my $toEmailAddress = $addresses->{'To'}->[0]->address;

Yes @panicjames.

On creation you choose to use Templates as simple or perl.
See: Customizing/Templates - RT 6.0.2 Documentation - Best Practical

Templates of type Perl are evaluated using Text::Template which allows arbitrary code execution.

Templates of type Simple permit only simple variable interpolation.