Topic
2 replies Latest Post - ‏2013-02-06T20:09:08Z by R.Friedel
SystemAdmin
SystemAdmin
111 Posts
ACCEPTED ANSWER

Pinned topic e-mail notification based on role

‏2013-01-16T03:03:37Z |
I'm trying to send e-mails based off of roles using Change 5.3. Is there a solution to resolve my issue?
Thank you.

-Jim
Updated on 2013-02-06T20:09:08Z at 2013-02-06T20:09:08Z by R.Friedel
  • SystemAdmin
    SystemAdmin
    111 Posts
    ACCEPTED ANSWER

    Re: e-mail notification based on role

    ‏2013-01-16T06:39:33Z  in response to SystemAdmin
    In a recent project I did this with a perl trigger that was invoked whenever the corresponding action took place.

    Below are some excerpts. I hope that all relevant information is included. If not, ask :)
    
    […] # role the user must have to be member of a CCB my $searchRole = 
    "ccb"; […]   #create a user object. Note the 
    "Admin" $aUser = 
    
    new ChangeSynergy::apiUser( $trigger->get_admin_user(), 
    "password", 
    "Admin", $trigger->get_admin_token(), $trigger->get_database() );   […] #################################################################################### sub get_email 
    { my $account = shift; print $debugfh 
    "suche mail fuer $account\n" 
    
    if $debugfh;   # decision: all recipients must be added to the local database, so the email address must exist in the LDAP server my $user_email; eval 
    { $user_email = $csapi->GetUserPreference( $aUser, $account, 
    "user_email" )->getResponseData(); 
    };   # currently, as the owner is identical to the submitter, it can occur that the email is not available # e.g. in remote sites. For the time being, 
    
    this is OK. Later, when owner is replaced by something # which is not automatically filled from Synergy, 
    
    this can lead to an error 
    
    if ($@) 
    { print 
    "Email address for $account was not defined in LDAP, cannot send out an email\n"; $user_email = 
    "NOADRFOUND"; 
    } print $debugfh 
    "habe mail: ist $user_email\n" 
    
    if $debugfh; 
    
    return lc($user_email); 
    }     #################################################################################### sub extract_all_ccb_role_user_mails 
    {   # get all users with the role ccb, then their emails.   # get CM-roles of all  users my $queryString = 
    "(name='base') and (type = 'model')";   #Create the requested attributes variable. my $requestedAttrs = 
    "users"; my @userlist;   #Eval block is used 
    
    for error handling. eval 
    {   #Run the QueryData method to recieve a data report. #Pass in the user object, report name, query string, query name, report title, template name and attribute list. my $results = $csapi->QueryData( $aUser, 
    "Basic Summary", $queryString, undef, undef, undef, $requestedAttrs );   unless ( 1 == $results->getDataSize() ) 
    { die 
    "How can I have more than one \'base - model\' objects in a database?"; 
    } @userlist = split /\n/, $results->getDataObject(0)->getDataObject(0)->getValue(); print $debugfh 
    "found $#userlist users in the db\n" 
    
    if $debugfh; 
    }; 
    
    if ($@) 
    { die 
    "problem with user list"; 
    }   # find all users that have the role $searchRole # each entry usually has the format # user <userid> = <role1> <role2> <...>; my @ccb_users; foreach (@userlist) 
    { push @ccb_users, $1 
    
    if (/^\s*user\s+(.*?)\s*=.*\b$
    {searchRole
    }\b/); 
    }   print $debugfh 
    "found the following CCB users: " . join( 
    ',', @ccb_users ) . 
    "\n" 
    
    if $debugfh;   # now get the emails and 
    
    return the result list. 
    
    return map 
    { get_email($_) 
    } @ccb_users;   
    } […]   ############## MAIL ################# ### add information about duplicates #####################################   
    
    if ( defined($crstatus) and $crstatus eq 
    "duplicate" ) 
    { $mailtxt .= 
    "<p/><p/><table border=1><tr><td><b>Duplicate CR</b></td><td><b>Synopsis</b></td></tr>"; my @dup_crs = get_duplicates_of($problem_number); foreach my $cr (@dup_crs) 
    { $mailtxt .= 
    "<tr>"; foreach my $value (@$cr) 
    { $mailtxt .= 
    "<td>$value</td>"; 
    } $mailtxt .= 
    "</tr>"; 
    } $mailtxt .= 
    "</table>"; 
    }   $mailtxt .= 
    "</html>"; print $debugfh $mailtxt 
    
    if $debugfh;   ############### MAIL ################# ### send ######################################   my $from = $trigger->get_from_email_addr(); die 
    "Sending of Mail not possible. Update entry [CCM_SYSTEM][FROM_EMAIL_ADDRESS] in pt.cfg\n" unless $from; my $smtp_srv = $trigger->get_smtp_server(); die 
    "Sending of Mail not possible. Update entry [CCM_SYSTEM][SMTP_SERVER] in pt.cfg\n" unless $smtp_srv; # 
    
    if we work in a test database, we 
    
    do not want to bother all CCBs regularly. # So, just pretend to send mails. 
    
    if ( $trigger->get_database() =~ m/test/ ) 
    { print 
    "\nwould have sent mail\n"; print 
    "from address: $from\n"; print 
    "via server: $smtp_srv\n"; print 
    "to recipients: $recipients\n"; print 
    "with subject: $subject\n"; print 
    "with text: \n$mailtxt\n"; print 
    "EOM\n"; remove_email_recipients() 
    
    if $remove_email_recipients; exit 0; 
    }   #Now we have determined that an email should be sent. #Create the mail object and pass it the smtp server name. my $sender = 
    
    new Mail::Sender 
    { smtp => $smtp_srv
    };   #open a connection to the stmp server and start sending information. $sender->Open( 
    { from     => $from, to       => $recipients, subject  => $subject, ctype    => 
    "text/html;charset=UTF-8", encoding => 
    "Quoted-printable" 
    } ) or die $Mail::Sender::Error, 
    "\n";   #Create the body of the message.  This message generates the link to the problem as 
    
    if it were #the same type of link from a CS report.  The database and problem number must be URL escaped, #thus the use of the CGI::escape function. $sender->SendEnc($mailtxt);   remove_email_recipients() 
    
    if $remove_email_recipients; #close DEBUG; exit 0;
    
  • R.Friedel
    R.Friedel
    2 Posts
    ACCEPTED ANSWER

    Re: e-mail notification based on role

    ‏2013-02-06T20:09:08Z  in response to SystemAdmin
    Jim,

    you may want to look at the out-of-the-box transition_notice.pl (perl) trigger that comes with a bunch of notification "templates" that can be configured for your needs.
    Have a look at the ECP process, which comes with a default set of templates (after you installed it) \wsconfig\templates\pt\forms\notification_templates ..

    More under:
    https://www.ibm.com/developerworks/mydeveloperworks/blogs/nfrsblog/entry/setting_up_email_notification_in_rational_change_v5_3_v5_23?lang=en

    Hope that helps,
    -Rudi.