Friday, 23 May 2025

Send Email getting template from Generic Template

 


Function ITS_SEND_MAIL(&EMPLID As string, &name As string, &TITLE As string, &SUBJECT As string, &CATALOG_NBR As string, &STRM As string, &Stdemail As string, &crse_id As string, &percentage As number)

   

   /* import the package */

   

   Local array of string &aBindVariables;

   Local array of PT_WF_NOTIFICATION:NotificationAddress &oNotifyTo, &oNotifyCc, &oNotifyBcc;

   Local PT_WF_NOTIFICATION:NotificationAddress &oNotifyAddr, &oCcAddr, &oBccAddr;

   Local PT_WF_NOTIFICATION:Notification &oNotif;

   /* Create an array of to-email ids for the Notification class */

   

   

   &emailsaddress = get_instr_email(&STRM, &crse_id);

   

   &oNotifyTo = CreateArrayRept(&oNotifyAddr, 0);

   &oNotifyCc = CreateArrayRept(&oCcAddr, 0);

   &oNotifyBcc = CreateArrayRept(&oBccAddr, 0);

   rem &sToEmail = "Testing_" | &Stdemail | "test";

   Warning &Stdemail;

   &sToEmail = &Stdemail;

   rem  &sToEmail = "munib776@yahoo.com";

   

   &sCcEmail = "munib776@yahoo.com" | &emailsaddress;

   

   &sBccEmail = "";

   /* NotificationAddress(Oprid, Description, Language, to-email-id, Channel) */

   &oNotifyAddr = create PT_WF_NOTIFICATION:NotificationAddress("", "", "", &sToEmail, "Email");

   &oNotifyTo.Push(&oNotifyAddr);

   /* Add CC recipient */

   &oCcAddr = create PT_WF_NOTIFICATION:NotificationAddress("", "", "", &sCcEmail, "Email");

   &oNotifyCc.Push(&oCcAddr);

   /* Add BCC recipient */

   &oBccAddr = create PT_WF_NOTIFICATION:NotificationAddress("", "", "", &sBccEmail, "Email");

   &oNotifyBcc.Push(&oBccAddr);

   /* instantiate the NotificationTemplate class */

   /* NotificationTemplate(component-name, component-market, Generic-template-name, G = Generic Template) */

   &oGenericTemplate = create PT_WF_NOTIFICATION:NotificationTemplate("", "", "ITS_STD_ABS_NOTF", "G");

   /* create an array of all bind variables */

   &aBindVariables = CreateArrayRept("", 0);

   &aBindVariables.Push(&name);

   &aBindVariables.Push(&EMPLID);

   &aBindVariables.Push(&crse_id);

   &aBindVariables.Push(&TITLE);

   &aBindVariables.Push(&SUBJECT);

   &aBindVariables.Push(&CATALOG_NBR);

   &aBindVariables.Push(&percentage);

   /* use the array of bind variables to populate the generic template */

   &xmlVars = &oGenericTemplate.SetupGenericVars(&aBindVariables);

   &oGenericTemplate.GetAndExpandTemplate(%Language, &xmlVars);

   /* instantiate the Notification class */

   /* Notification(Notify-from-email-id, date-time, language) */

   &oNotif = create PT_WF_NOTIFICATION:Notification("noreply@machs.edu.sa", %Date + %PerfTime, %Language);

   /* set properties */

   &oNotif.ContentType = "Content-type: text/html; charset=US-ASCII";

   &oNotif.NotifyTo = &oNotifyTo;

   &oNotif.NotifyCC = &oNotifyCc;

   &oNotif.NotifyBCC = &oNotifyBcc;

   &oNotif.EmailReplyTo = ""; /* see note 1 */

   &oNotif.Subject = &oGenericTemplate.Subject;

   &oNotif.Message = &oGenericTemplate.Text; /* see note 2 */

   /* send email */

   &oNotif.Send();

End-Function;



No comments:

Post a Comment