[rt-users] Send email from script

Tariq Doukkali tariq.doukkali at autoform.de
Wed Jul 22 04:07:37 EDT 2009


Hi Ashish,

The script is working fine !!! Now I can send messages from a script directly. But I don't know how to modify the subject of the message (email) ?? 

Many thanks for your help

Best regards from Germany,
Tariq

-----Ursprüngliche Nachricht-----
Von: Potla, Ashish Bassaliel [mailto:c_apotla at qualcomm.com] 
Gesendet: Mittwoch, 22. Juli 2009 09:11
An: Tariq Doukkali
Cc: rt-users at lists.bestpractical.com
Betreff: RE: [rt-users] Send email from script

Here is a sample :

Description : On Correspond
Condition: On Correspond
Action: User Defined
Template:Global Template : QCT Transaction
Stage: Transaction Batch

Custom Action Prep Code:

------------

require RT::Action::SendEmail;
use strict;
use vars qw/@ISA/;
@ISA = qw(RT::Action::SendEmail);
$self->SetRecipients();
$self->SUPER::Prepare();
$self->SUPER::Commit();

sub SetRecipients {
    my $self = shift;
    my $ticket = $self->TicketObj;
    my ( @To, @PseudoTo, @Cc, @Bcc );
    my $arg ='Owner,Requestor,AdminCc,Cc';
    
  
   ##Requestor
    push @To, $ticket->Requestors->MemberEmailAddresses;
    
    ##CC
    push ( @Cc, $ticket->Cc->MemberEmailAddresses );
    push ( @Cc, $ticket->QueueObj->Cc->MemberEmailAddresses  );

    ##Admin CC
    push ( @Bcc, $ticket->AdminCc->MemberEmailAddresses  );
    push ( @Bcc, $ticket->QueueObj->AdminCc->MemberEmailAddresses  );
    
    ##Owner
    push ( @Bcc, $ticket->OwnerObj->EmailAddress );
    
    ##Other Recipients
    if ( my $attachment = $self->TransactionObj->Attachments->First ) {
        push @Cc, map { $_->address } Email::Address->parse($attachment->GetHeader('RT-Send-Cc'));
        push @Bcc, map { $_->address } Email::Address->parse($attachment->GetHeader('RT-Send-Bcc'));
    }
    
    ##FriendlyToLineFormat
    if ( RT->Config->Get('UseFriendlyToLine') ) {
        unless (@To) {
            push @PseudoTo,
                sprintf RT->Config->Get('FriendlyToLineFormat'), $arg, $ticket->id;
        }
    }
    
    
    my $creator = $self->TransactionObj->CreatorObj->EmailAddress();
    #Strip the sender out of the To, Cc and AdminCc and set the 
    # recipients fields used to build the message by the superclass.
    # unless a flag is set 
    if (RT->Config->Get('NotifyActor')) {
        @{ $self->{'To'} }  = @To;
        @{ $self->{'Cc'} }  = @Cc;
        @{ $self->{'Bcc'} } = @Bcc;
    }
    else {
        @{ $self->{'To'} }  = grep ( lc $_ ne lc $creator, @To );
        @{ $self->{'Cc'} }  = grep ( lc $_ ne lc $creator, @Cc );
        @{ $self->{'Bcc'} } = grep ( lc $_ ne lc $creator, @Bcc );
    }
}
1;

------------
Custom Action Cleanup Code:
------------
return 1;
------------

This is how I send emails from scrips when I donot want to touch the database ie create new scripactions on the database.
Needless to say the above scrip is equivalent to On correspond , Notify Requestor, Owner, AdminCC, CC, Other Recepients. 

hope this helps.
-Ashish

________________________________________
From: Tariq Doukkali [tariq.doukkali at autoform.de]
Sent: Wednesday, July 22, 2009 11:27 AM
To: Potla, Ashish Bassaliel
Cc: rt-users at lists.bestpractical.com
Subject: AW: [rt-users] Send email from script

Hi Ashish,

many Thanks for your answer !!!!

I want sent an email from a user defined action, but I don't know how can I do that ;-((

Tariq

-----Ursprüngliche Nachricht-----
Von: Potla, Ashish Bassaliel [mailto:c_apotla at qualcomm.com]
Gesendet: Dienstag, 21. Juli 2009 20:35
An: Gene LeDuc; Tariq Doukkali
Cc: rt-users at lists.bestpractical.com
Betreff: RE: [rt-users] Send email from script

You can actually send out emails via scrips with user defined scrip-Action.

The action is but a bit longwinded, but I use it for some of  my queues to tweak the outgoing emails (Like add/remove an email id from the outgoing email for all email transactions -- for instance).

Let me know if you want the user defined action.

-Ashish

________________________________________
From: rt-users-bounces at lists.bestpractical.com [rt-users-bounces at lists.bestpractical.com] On Behalf Of Gene LeDuc [gleduc at mail.sdsu.edu]
Sent: Tuesday, July 21, 2009 11:32 PM
To: Tariq Doukkali
Cc: rt-users at lists.bestpractical.com
Subject: Re: [rt-users] Send email from script

Hi Tariq,

The obvious answer: You select one of the Notify actions that generate
e-mail and use a template to design the e-mail.

But you probably would've figured that out for yourself.

If you are asking how to send an e-mail from a scrip with a user-defined
action, I don't think you can.  I get around this shortcoming by
generating some other transaction in the script code and then use that
transaction to trigger a scrip that does the Notify action.  Convoluted,
but it works.

We don't use the Priority field in our tickets, so I use it to trigger
stuff like that.

Have fun!
Gene

Tariq Doukkali wrote:
> Hello,
>
> how can I send an email from a script ???
>
> Many thanks

_______________________________________________
http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-users

Community help: http://wiki.bestpractical.com
Commercial support: sales at bestpractical.com


Discover RT's hidden secrets with RT Essentials from O'Reilly Media.
Buy a copy at http://rtbook.bestpractical.com



More information about the rt-users mailing list