[rt-users] Modify MIME::Entity Template Data from Scrip

Foggi, Nicola NFOGGI at depaul.edu
Fri Nov 6 16:30:40 EST 2009


just incase anyone else looks for the answer:

$MIMEObj->bodyhandle(new MIME::Body::InCore $ticketcontent);

will do it...

Nicola

-----Original Message-----
From: rt-users-bounces at lists.bestpractical.com on behalf of Foggi, Nicola
Sent: Fri 11/6/2009 1:00 PM
To: rt-users at lists.bestpractical.com
Subject: [rt-users] Modify MIME::Entity Template Data from Scrip
 

Hey Everyone,

I'm working on a scrip that when an approval is approved and the parent ticket switches to "open" it emails a budget manager with the original pdf attachment of the quote, and the contents of the original request that went for approval.

I've gotten the attachment working by using some code from the mailing lists to create the email via a scrip:

        $MIMEObj->make_multipart('mixed');
        $MIMEObj->attach(
            Type     => $a->ContentType,
            Charset  => $a->OriginalEncoding,
            Data     => $a->OriginalContent,
            Filename => $a->Filename,
            Encoding => '-SUGGEST'
       );

i use load a template into the scrip and use it to send the email:

my $template = RT::Template->new($RT::SystemUser);
  $template->LoadQueueTemplate(Queue => $Queue->id, Name => $templatename);

     unless ( $template->Id ) {
         $RT::Logger->crit(qq(Unable to load queue $Queue->id template $templatename));
		die qq([ERROR] Unable to load queue $Queue->id template $templatename\n);
     }

... cropped ...

     if ( $RT::MailCommand eq 'sendmailpipe' ) {
         eval {
             open( MAIL, "|$RT::SendmailPath $RT::SendmailArguments" ) 
|| die $!;
             print MAIL $MIMEObj->as_string;
             close(MAIL);
         };
         if ($@) {
             $RT::Logger->crit("Could Not Send Purchaser Email. -" . $@ );
             die("[ERROR] Could Not Send Purchaser Email. -" . $@ );
		}
     }
     else {
         my @mailer_args = ($RT::MailCommand);

         local $ENV{MAILADDRESS};

         if ( $RT::MailCommand eq 'sendmail' ) {
             push @mailer_args, split(/\s+/, $RT::SendmailArguments);
         }
         elsif ( $RT::MailCommand eq 'smtp' ) {
             $ENV{MAILADDRESS} = $RT::SMTPFrom || $MIMEObj->head->get('From');
             push @mailer_args, ( Server => $RT::SMTPServer );
             push @mailer_args, ( Debug  => $RT::SMTPDebug );
         }
         else {
             push @mailer_args, $RT::MailParams;
         }

         unless ( $MIMEObj->send(@mailer_args) ) {
             $RT::Logger->crit("Could Not Send Purchaser Email." );
             die "[ERROR] Could Not Send Purchaser Email.\n";
         }
     }


the problem i'm running into is i now can't get access to perl in the template, i'm guessing i'm missing something, so i thought well maybe I could use the MIMEObj in the scrip to access the body of the message and insert the "$Ticket->Transactions->First->Content()" but I can't figure out how to replace it.  I used MIMEObj->bodyhandle( xxx ) but that didn't seem to do it.

Any thoughts?

Nicola

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20091106/1bf863fc/attachment.htm>


More information about the rt-users mailing list