Creating a Text Email
The following code example creates and sends a very simple email, then tests the results.
import PT_MCF_MAIL:*;
/*-- Create an outbound email object --*/
Local PT_MCF_MAIL:MCFOutboundEmail &eMail =
create PT_MCF_MAIL:MCFOutboundEmail();
/*-- Initialize the usual fields of an email --*/
&eMail.From = &FromAddress;
&eMail.Recipients = &ToList;
&eMail.Subject = &Subject;
&eMail.Text = &MailBody;
/*-- 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;
Creating Email and Overriding SMTP Settings
The following code example creates a text email and overrides the SMTP settings as found in the application server configuration file.
import PT_MCF_MAIL:*;
/*-- Create an email object by setting individual parameters ---*/
Local PT_MCF_MAIL:MCFOutboundEmail &eMail =
create PT_MCF_MAIL:MCFOutboundEmail();
&eMail.Recipients = &ToList; /* comma separated list of email addresses */
&eMail.CC = &CCList; /* comma separated list of email addresses */
&eMail.BCC = &BCCList; /* comma separated list of email addresses */
&eMail.From = &FromAddress; /* from email address */
&eMail.ReplyTo = &ReplyToAddress; /* in case the reply is to be sent to a
different email address */
&eMail.Sender = &SenderAddress; /* If different from the "from" address */
&eMail.Subject = &Subject; /* email subject line */
&eMail.Text = &MailBody; /* email body text */
/*-- Override the default SMTP parameters specified in app server configuration file ----*/
&eMail.SMTPServer = "psp-smtpg-01";
&eMail.SMTPPort = 10266; /*-- Usually this is 25 by default */
Local integer &resp = &eMail.Send();
/* Now check the &resp for the result */
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;
Creating a Multipart Email with Text and HTML Parts
The following code example creates an email with both HTML and text sections.
The email client on the target host must be able to detect the HTML and text parts in the email and display the part that the client is configured to display.
import PT_MCF_MAIL:*;
Local PT_MCF_MAIL:MCFOutboundEmail &email =
create PT_MCF_MAIL:MCFOutboundEmail();
Local string &TestName = "Text and its alternate html body";
&email.From = &FromAddress;
&email.Recipients = &ToList;
&email.Subject = &Subject;
Local PT_MCF_MAIL:MCFBodyPart &text = create PT_MCF_MAIL:MCFBodyPart();
&text.Text = "Hi There";
Local PT_MCF_MAIL:MCFBodyPart &html = create PT_MCF_MAIL:MCFBodyPart();
&html.Text =
"<html><BODY><H1>EMail test with HTML content</H1><b>Hi There</b>" |
"<A href='http://www.peoplesoft.com'>Check this out!</A>" |
"<P></BODY></html>";
&html.ContentType = "text/html";
Local PT_MCF_MAIL:MCFMultipart &mp = create PT_MCF_MAIL:MCFMultipart();
&mp.SubType = "alternative; differences=Content-type";
&mp.AddBodyPart(&text);
&mp.AddBodyPart(&html);
&email.MultiPart = ∓
Local integer &res = &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;
Sending PDF as attachment in 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();
Local PT_MCF_MAIL:MCFBodyPart &text = create PT_MCF_MAIL:MCFBodyPart();
&email.Recipients = "HCMGENUser5@ap6023fems.us.oracle.com";
&email.From = "SMTPUser@oracle.com";
&email.BCC = "";
&email.Subject = "MCF Outbound Email of PDF test";
&email.ReplyTo = "";
&text.Text = "Email Body - This is a Test of the MCF Outbound Email, attaching pdf file";/*** Add Attachment - Start ***/
Local PT_MCF_MAIL:MCFMultipart &mp = create PT_MCF_MAIL:MCFMultipart();
Local PT_MCF_MAIL:MCFBodyPart &attach = create PT_MCF_MAIL:MCFBodyPart();
&attach.SetAttachmentContent("/home/psadm2/ps/pt/8.50/appserv/prcs/PRCSDOM/MCF-Email-Pcode.pdf", %FilePath_Absolute, "Test.pdf", "Test.pdf", "", "");
&attach.Disposition = "attachment";
&mp.AddBodyPart(&text);
&mp.AddBodyPart(&attach);
&email.MultiPart = ∓/*** Add Attachment - End ***/
/*** Send the Email ***/
&res = &email.Send();
/*** Check the Email made the trip ***/
Local boolean &done;
Evaluate &res
When %ObEmail_Delivered
/* every thing ok */
&done = True;
Exit 0;
When %ObEmail_NotDelivered
/*-- Check &email.InvalidAddresses, &email.ValidSentAddresses
and &email.ValidUnsentAddresses */
&done = False;
Exit 1;
When %ObEmail_PartiallyDelivered
/* Check &email.InvalidAddresses, &email.ValidSentAddresses
and &email.ValidUnsentAddresses; */
&done = True;
Exit 1;
When %ObEmail_FailedBeforeSending
/* Get the Message Set Number, message number;
Or just get the formatted messages from &email.ErrorDescription,
&email.ErrorDetails;*/
&done = False;
Exit 1;
End-Evaluate;