Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Request Tracker: Users

Modify MIME::Entity Template Data from Scrip

 

 

Request Tracker users RSS feed   Index | Next | Previous | View Threaded


NFOGGI at depaul

Nov 6, 2009, 11:00 AM

Post #1 of 2 (143 views)
Permalink
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


NFOGGI at depaul

Nov 6, 2009, 1:30 PM

Post #2 of 2 (126 views)
Permalink
Re: Modify MIME::Entity Template Data from Scrip [In reply to]

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

Request Tracker users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.