How do I invoke token substitution with Pet? I have to send some emails in a custom Drupal 7 module.

I'd like to use the PET module (Previewable email templates) to manage the templates and drupal_mail() to send emails because it already uses SwiftMailer to send emails.
The problem is that the body of the email I get from Pet has some tokens that I should replace before the email is sent.

How can I replace them?

This is the code I'm using.

$pet = pet_load('test1');

$params['format']= "text/html";
$params['charset']= "UTF-8";
$params['email_subject']= $pet-&gt;subject;
$params['email_body']=$pet-&gt;mail_body;

///$params['email_body']= &lt;body with token replaced&gt;

drupal_mail('myLib', 'customNotifications', 'xxx@gmail.com', language_default(), $params);
I've solved in this way:

// SOSTITUZIONE TOKEN DRUPAL
$l_oPetTemplate = pet_load('test1');
$l_TemParams2['pet'] = $l_oPetTemplate;
$l_aSubstitutions = pet_substitutions($l_oPetTemplate, $l_TemParams2);
$l_aEmailParams['email_subject'] = token_replace($l_oPetTemplate-&gt;subject, $l_aSubstitutions, array('clear' =&gt; TRUE));
$l_aEmailParams['email_body']=token_replace($l_oPetTemplate-&gt;mail_body, $l_aSubstitutions, array('clear' =&gt; TRUE));