Sending EMAILS in PeopleSoft - Deep Dive !! - Different Options and Other details

Sending an email is very simple and easy concept, but there are so many different things that we need to keep in mind from best practices to new additional methods that can be useful in different purpose. I am trying to cover all the different aspects of sending emails, this will be Bible for sending emails in the PeopleSoft.

Best Practice
1)  Anything that works is not correct or best method to follow while writing the PeopleCode. First thing comes to the mind - SendMail function to send the email, it is an deprecated method and should not be used. Application Class MCFOutboundEmail needs to be used and it is the fully SMTP Protocol compliant to RFC 821/822. It uses Javamail functionality using this package.

Where to Configure
MCFOutBoundEmail() function uses the SMTP section of the Application Server's psappsrv.cfg file, and Process Scheduler's SMTP section of the psprcs.cfg file, just as the SendMail() function does. No special configuration is required for the MCFOutboundEmail() function to work.

Sample Code send Email
import PT_MCF_MAIL:*;
import PT_MCF_MAIL:MCFOutboundEmail;
import PT_MCF_MAIL:MCFEmail;
Local PT_MCF_MAIL:MCFOutboundEmail &email = create PT_MCF_MAIL:MCFOutboundEmail();
&email.Recipients = "";
&email.From = "";
&email.BCC = "";
&email.Subject = "MCF Outbound Email test";
&email.ReplyTo = "";
&email.Text = "Email Body - This is a Test of the MCF Outbound Email";
&res = &email.Send();

Best Performance for sending Bulk email 
 if you need to send several emails where content is specific to each email is different. Following code will help if you need to send email notification on the component peoplecode, as it make one SMTP connection to send all the emails and performance will be better.
import PT_MCF_MAIL:MCFOutboundEmail;
import PT_MCF_MAIL:MCFBodyPart;
import PT_MCF_MAIL:MCFMultipart;
import PT_MCF_MAIL:MCFMailUtil;
import PT_MCF_MAIL:SMTPSession;
Local integer &noOfMails = 20;
Local array of PT_MCF_MAIL:MCFOutboundEmail &mails;
Local PT_MCF_MAIL:MCFOutboundEmail &email;
Local integer &i;
Local PT_MCF_MAIL:SMTPSession &commonSession = create PT_MCF_MAIL:SMTPSession();
&commonSession.Server = "";
&commonSession.Port = 25;
&mails = CreateArray(&email);
For &i = 1 To &noOfMails
&email = &commonSession.CreateOutboundEmail();
&email.From = "";
&email.Recipients = "";
&email.BCC = "";
&email.Subject = "Mail: " | NumberToString("2.0", &i) | " Hi there";
&email.Text = "Mail No: " | NumberToString("2.0", &i) | "One of multiple mails from from java";
&email.ContentType = "text/html";
&mails &i = &email;

Local PT_MCF_MAIL:MCFMailUtil &util = create PT_MCF_MAIL:MCFMailUtil();
Local array of integer &allRes = &commonSession.SendAll(&mails);

In case if mails are not working for you and you are not able to figure out the issue.
You should look into smtp logs for more details and it will tell you exactly what is happening.
Before using the SMTP logs , you need to enable it.
For enabling SMTP logs for App Server you need to edit the app server configuration file :psappsrv.cfg.
Open the psappsrv.cfg file  and find “SMTP”.Look for SMTPTrace variable.
It will be SMTPTrace=0 initially.

Set the value of this variable SMTPTrace=1 and save the file.
This change does not require a Application Server boot and changes will be reflected immediately.
If you are using mail classes from Process Scheduler, you may need to set their trace also.
The psprcs.cfg file needs to be modified for this.
Open the file and look for SMTP and change the settings as done in the App server configuration file.
It will generate Trace file SMTP.LOG in LOGS Folder under
$PS_HOMEappservdomain_namelogsSMTP.LOG  for Appserver and $PS_HOMEappservprcsdomain_namelogsSMTP.LOG for Batchserver.

Creating an Email from Rich Text Editor Output
Using the ParseRichTextHTML - you can send the Rich Text with messages. Follwoing link has the complete details of the sample code.

Validating Email Address
ValidateAddress(addresslist) - Use the ValidateAddress method to validate a comma- or semicolon-separated list of email addresses. This method checks the syntax of the email address. It does not verify the domain name or the validity of the user name.
import PT_MCF_MAIL:*;
&emailutil = create PT_MCF_MAIL:MCFMailUtil();
Local boolean &result = &emailutil.ValidateAddress(&email.Recipients);
Local array of string &bAddresses = &emailutil.badaddresses;
If (&result = False) Then
If (&bAddresses <> Null) Then
&i = 0;
While &bAddresses.Next(&i)
Warning ("Bad email address in input = " | &bAddresses [&i]);

Creating an HTML Email with Images
Sending the HTML content and sending the Client Image may be requried. It looks good to send them in the email, Rather than the boring static emails which doesn't have much of details in it.
Following link has the details of the code to send the same.

2)  Notification Framework Another option is not explored very well by developers to send emails.  It can be easy way sending the email for many scenarios, where code can be simple and  provide configurable options.

The Notifications Framework uses the generic templates of the PeopleTools Workflow Technology, and the reader is urged to review the information in PeopleTools: Workflow Technology, “Using Notification Templates,” for a more comprehensive understanding.

 Entity Registry to generalize all notifications into a single structure. The architecture is modeled on a pluggable channel-based approach. Each notification type is supported by a dedicated channel that supports the idiosyncrasies of the particular notification type.

After creating Templates

PeopleTools, then select  Workflow, then selectNotifications, then selectGeneric Templates 

Notification Setup page (select Set Up SACR, then select System Administration, then select Utilities, then select Notifications, then select Notification Setup)

Notification Consumer Setup page (select Set Up SACR, then select System Administration, then select Utilities, then select Notifications, then select Notification Consumer Setup).

Write an AppClass that extends AbstractNotification class. The Consumer ID must be passed to the Super Class constructor
Implement the abstract method createNtfContext().
Implement the abstract method populateNtfContext(). This method populates the context create above with the necessary values 
Invoke the send(), remind(), or resend() methods.
Override the OnSuccess() and OnError() for custom behavior

Consultants can refer to the Delegated Access Application Class SCC_DA:NOTIFY as a reference for how to trigger the Notifications Framework as a consumer.