Sending Mails using Generic Templates



Send Mail using Generic Templates


import PT_WF_NOTIFICATION:NotificationAddress;
import PT_WF_NOTIFICATION:Notification;
import PT_WF_NOTIFICATION:NotificationTemplate;
import PT_MCF_MAIL:*;
import PT_MCF_MAIL:MCFOutboundEmail;
import PT_MCF_MAIL:MCFEmail;

Local array of string &aryValues;
Local array of PT_WF_NOTIFICATION:NotificationAddress &mynotifyto;
Local PT_WF_NOTIFICATION:NotificationAddress &mynotifyaddress;
Local PT_WF_NOTIFICATION:Notification &mynotification;
Local string &emailid, &Template_Name;


/* Email Applicant START*/
&mynotifyto = CreateArrayRept(&mynotifyaddress, 0);
SQLExec("select EMAIL_ADDR from PS_EMAIL_ADDRESSES where EMPLID=:1 AND PREF_EMAIL_FLAG='Y' AND E_ADDR_TYPE='CAMP'", N_SR_EXT016_VW.EMPLID.Value, &emailid);
&mynotifyaddress = create PT_WF_NOTIFICATION:NotificationAddress("", "", "", &emailid, "Email");
If All(&emailid) Then
   &mynotifyto.Push(&mynotifyaddress);
   &Template_Name = "N_STDNT_AWARD";
   &mynotifytemplate = create PT_WF_NOTIFICATION:NotificationTemplate("", "", &Template_Name, "G");
   
   /* Populate an array to contain the values needed by the template */
   &aryValues = CreateArrayRept("", 0);
   
   &aryValues.Push(&EmplName);
   &aryValues.Push(&CalcBrndDescr);
   &aryValues.Push(&CalcMdlDescr);
   &aryValues.Push(&Effdt);
   
   &xmlVars = &mynotifytemplate.SetupGenericVars(&aryValues);
   &mynotifytemplate.GetAndExpandTemplate(%Language, &xmlVars);
   &mynotification = create PT_WF_NOTIFICATION:Notification(" ", %Date + %PerfTime, %Language);
   
   &mynotification.NotifyTo = &mynotifyto;
   &mynotification.ContentType = "Content-type: text/html; charset=US-ASCII";
   &mynotification.Subject = &mynotifytemplate.Subject;
   &mynotification.Message = &mynotifytemplate.Text;
   &mynotification.Send();
End-If;