Topic
  • 7 replies
  • Latest Post - ‏2013-12-17T23:32:58Z by DonaldN
melshah
melshah
72 Posts

Pinned topic Email Notification perl code

‏2013-12-05T19:17:41Z |

Hello,

Can anyone let me know how to write perl code for sending email notification on state changed to complete only if submitter is "XYZ"

Do not want to use Email Rules as the field value is customized . In description also some wordings are appended

And the notification should be able to trigger from both web and CQ thick client. I am using CQ 7.1.1

1. Fire Email notification on Action complete

2.Check if the submitter is "XYZ"

3. get field values and customize it

4. send the mail to submitter

can someone provide perl snippet example for notification hook

I see one example in google should it be good ?

use Net::SMTP;
 
 $MAILHOST = "smtprelay.myserver.com";
$EMAIL = "myname\@us.ibm.com";
$smtp = Net::SMTP->new("$MAILHOST");
$smtp->mail("DeploymentGuard\@DONOTREPLY.COM");
$smtp->to("$EMAIL");
$smtp->data();
$smtp->datasend("To: $EMAIL\n");
$smtp->datasend("Subject: Testing Email Notification Hook \n");
$smtp->datasend("my test message");
$smtp->dataend();
$smtp->quit();


 
 

  • pdubovitsky
    pdubovitsky
    376 Posts

    Re: Email Notification perl code

    ‏2013-12-05T19:22:26Z  

    You can try Email Notification package:

    http://cqadmin.org/wiki/ClearQuest_Email_Notification_Package

    Pavel

  • DonaldN
    DonaldN
    287 Posts

    Re: Email Notification perl code

    ‏2013-12-05T23:49:47Z  

    There are plenty of sample codes in ClearQuest InfoCenter to get you going. You will need the MailMsg object to send out emails.

    http://pic.dhe.ibm.com/infocenter/cqhelp/v8r0m0/topic/com.ibm.rational.clearquest.apiref.doc/topics/c_mailmsg_ovw.htm

  • CQAdmin
    CQAdmin
    103 Posts

    Re: Email Notification perl code

    ‏2013-12-06T03:54:10Z  

    Please have a look on the below tech note..

    http://www-01.ibm.com/support/docview.wss?uid=swg21641874

     

    In the hook code $name will have the value of "submitter". You can use if condition here. If $name has a value "XYZ" then only process the below code or else nothing.

    All the Best

    :)

     

    Further, you can check the recently published tech notes on ClearQuest APIs here-

    https://www.ibm.com/developerworks/community/blogs/nfrsblog/entry/recently_published_tech_notes_on_clearquest_apis?lang=en

    https://www.ibm.com/developerworks/community/blogs/nfrsblog/entry/recently_published_tech_notes_on_ibm_rational_clearquest_apis_2?lang=en

  • melshah
    melshah
    72 Posts

    Re: Email Notification perl code

    ‏2013-12-06T19:05:44Z  

    Thank you this will get me going

  • CQAdmin
    CQAdmin
    103 Posts

    Re: Email Notification perl code

    ‏2013-12-09T02:45:19Z  
    • melshah
    • ‏2013-12-06T19:05:44Z

    Thank you this will get me going

    You are Welcome

    :)

  • melshah
    melshah
    72 Posts

    Re: Email Notification perl code

    ‏2013-12-17T20:05:50Z  
    • CQAdmin
    • ‏2013-12-09T02:45:19Z

    You are Welcome

    :)

    Hello,

    So i was able to write the perl email notification code and it worked , I have a question though how do i set  multiple lines in email body

    like in the body of the message i would like to send multiple filed values and than add some custom notes in the end of the body . Do i need to set multiple variables get field values in them and keep doing

    $headline= "This is Headline"
    $body=" this is body"
     $mailmsg->SetBody($body);
     $mailmsg->SetBody($headline);

    ====================================

    $name = $entity->GetFieldValue("Submitter")->GetValue();
        if ($name eq "HD" )
        {
          $session->OutputDebugString(" Sending email to Mehul. \n");

          $EntityObj = $session->GetEntity("users",$name);
          $Email = $EntityObj->GetFieldValue(email)->GetValue();
          $session->OutputDebugString(" User Email $Email \n.");
          $user_full_name = $EntityObj->GetFieldValue(fullname )->GetValue();
          $session->OutputDebugString(" user full name  $user_full_name \n.");

          my $mailmsg = CQMailMsg::Build();
        $mailmsg->AddTo($Email);

        # Write the subject line of the email here
        $Sub="A new Defect";
        $mailmsg->SetSubject($Sub);

        # Write the body of the email here
        $body = " A new Record has been submitted.\n\n";
        $mailmsg->SetBody($body);

        # Sending the email
        $mailmsg->Deliver();
        CQMailMsg::Unbuild($mailmsg);

         }
    }

  • DonaldN
    DonaldN
    287 Posts

    Re: Email Notification perl code

    ‏2013-12-17T23:32:58Z  
    • melshah
    • ‏2013-12-17T20:05:50Z

    Hello,

    So i was able to write the perl email notification code and it worked , I have a question though how do i set  multiple lines in email body

    like in the body of the message i would like to send multiple filed values and than add some custom notes in the end of the body . Do i need to set multiple variables get field values in them and keep doing

    $headline= "This is Headline"
    $body=" this is body"
     $mailmsg->SetBody($body);
     $mailmsg->SetBody($headline);

    ====================================

    $name = $entity->GetFieldValue("Submitter")->GetValue();
        if ($name eq "HD" )
        {
          $session->OutputDebugString(" Sending email to Mehul. \n");

          $EntityObj = $session->GetEntity("users",$name);
          $Email = $EntityObj->GetFieldValue(email)->GetValue();
          $session->OutputDebugString(" User Email $Email \n.");
          $user_full_name = $EntityObj->GetFieldValue(fullname )->GetValue();
          $session->OutputDebugString(" user full name  $user_full_name \n.");

          my $mailmsg = CQMailMsg::Build();
        $mailmsg->AddTo($Email);

        # Write the subject line of the email here
        $Sub="A new Defect";
        $mailmsg->SetSubject($Sub);

        # Write the body of the email here
        $body = " A new Record has been submitted.\n\n";
        $mailmsg->SetBody($body);

        # Sending the email
        $mailmsg->Deliver();
        CQMailMsg::Unbuild($mailmsg);

         }
    }

    You don't need to repeat every line of the code. What you need to do is to construct the entire mail content in $body before calling SetBody($body). So your code should have something like this:

    $body = "start of the mail\n";

    $body = $body . " some other stuff\n";

    $body = $body . " more stuff\n";

    ......

    If you have a variable containing the field value, just put the variable in the right place in the string. So it looks like this:

    $body = $body . "The Defect $id has been changed to state $newstate.\n";

    There are more ways to put strings together in Perl. Follow the link below for some samples.

    http://www.perlmonks.org/?node_id=32418