Here's a quick way to send an email message from within peoplecode. You can also send attachments along with your email message. Simply use the PeopleCode command SendMail to send an email message from a PeopleSoft page. You can simply copy this code and change the values with yours and you'll be sending mail in no time. This is very useful code to use within Application Engine.

 

REM ****************************************;
REM SEND MAIL MESSAGE;
REM ****************************************;

&FLAGS = 0;
&TO = "you@youremailaddress.com";
&CC = "";
&BCC = "me@myemailaddress.com";
&SUBJECT = "Sample Subject"
&TEXT = "This is a sample mail message."
&FILES = "C:\DATA\YOURFILE.TXT"

&RETURN_CODE = SendMail(&FLAGS, &TO, &CC, &BCC, &SUBJECT, &TEXT, &FILES, &TITLES);

If Not (&RETURNCODE = 0) Then
rem WinMessage("Here is the Return Code = " / &RETURNCODE);
End-If;

 

Another way to send email with email class.

import PT_MCF_MAIL:*;

 

/*-- Create an email object by setting individual parameters ---*/

Local PT_MCF_MAIL:MCFOutboundEmail &eMail = create PT_MCF_MAIL:MCFOutboundEmail();

Local string &emailaddress;

Local string &emailsentaddress;

Local string &text;

&emailaddress = "gyu@ataway.com";

&emailsentaddress = "98_degree@163.com";

&text = "text for test";

&eMail.Recipients = &emailaddress; /* comma separated list of email addresses */

&eMail.CC = &emailaddress; /* comma separated list of email addresses */

&eMail.BCC = &emailaddress; /* comma separated list of email addresses */

&eMail.From = &emailsentaddress; /* from email address */

&eMail.ReplyTo = &emailsentaddress; /* in case the reply is to be sent to a different email address */

&eMail.Sender = &emailsentaddress; /* If different from the "from" address */

 

&eMail.Subject = &text; /* email subject line */

&eMail.Text = &text; /* email body text */

 

/*-- Override the default SMTP parameters specified in app server configuration file ----*/

&eMail.SMTPServer = "smtp.163.com";

&eMail.SMTPPort = 25; /*-- 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;

For attachment, use the code below:

Local PT_MCF_MAIL:MCFBodyPart

&attach2 = create PT_MCF_MAIL:MCFBodyPart();
&attach2.SetAttachmentContent("///file:C:/User/Documentum/XML%20Applications/proddoc/peoplebook_upc/peoplebook_upc.dtd",%FilePath_Absolute, "Sample.jpg", "Sample", "", "");