Monday, February 26, 2018

How to send an Email utilizing PeopleCode

 /*-- Create an outbound email object --*/
     
      Local PT_MCF_MAIL:MCFOutboundEmail &eMail = create PT_MCF_MAIL:MCFOutboundEmail();

 /*-- Initialize the usual fields of an email --*/
     
      Local string &FromAddress;
      Local string &ToList;
      Local string &Subject;
      Local string &MailBody;
      Local string &EmailID;
      Local string &URL;
      Local string &USER_ID;
     
      SQLExec("Select EMAILID FROM PSOPRDEFN Where OPRID = %OperatorId", &EmailID);
     
      &FromAddress = "donotreply@peoplesoft.com";
      &ToList = &EmailID;
      &Subject = "Hello World";
      &MailBody = MsgGetExplainText(0, 0, "Message not found");
      &eMail.From = &FromAddress;
      &eMail.Recipients = &ToList;
      &eMail.Subject = &Subject;
      &eMail.Text = &MailBody;

 REM %Response.RedirectURL(&URL);
/*This code allows us to redirect to a different page once the Email has been sent.*/
     
 /*-- The send method uses the default SMTP parameters as set in the app server configuration file.

This send method makes a connection to the SMTP server, sends the mail and then disconnects.
The result are returned as a number corresponding to the possible values.

The list of ValidSent, InvalidSent and Invalid addresses are returned in the email object itself
 ----*/
     
      Local integer &resp = &eMail.Send();
      Local boolean &done;
     
      Evaluate &resp
      When %ObEmail_Delivered

/* every thing ok */

         &done = True;
         Break;
         
      When %ObEmail_NotDelivered

/*-- Check &email.InvalidAddresses, &email.ValidSentAddresses and  &email.ValidUnsentAddresses */

         &done = False;
         Break;
         
      When %ObEmail_PartiallyDelivered

/* Check &email.InvalidAddresses, &email.ValidSentAddresses and &email.ValidUnsentAddresses; */

         &done = True;
         Break;
         
      When %ObEmail_FailedBeforeSending
/* Get the Message Set Number, message number Or just get the formatted messages from &email.ErrorDescription, &email.ErrorDetails;*/
         
         &done = False;
         Break;
      End-Evaluate;

/* Email Success Notification*/
     
      MessageBox(0, "Email Success", 0, 0, "Message not found");
     
   End-If;
     

No comments:

Post a Comment

8 Steps To Building an Application in PeopleSoft

Designing the Application:             This is the most important step in creating an application; most of the time in creating an applicat...