PS发送邮件实例!

 

/* AREVA T&D – Project – Kevin He - 16/FEB/2009 – Begin */
/* Send email with payslip to the corresponding employee. */
import PT_MCF_MAIL:*;

Local File &File;
Local string &FILE_NAME;

rem This text is used to debug email distribution
&FILE_NAME = "debug_email.txt";
&CHARSET = "U";
&File = GetFile(&FILE_NAME, "W", &CHARSET);

&retcode = 100;
Local PT_MCF_MAIL:MCFOutboundEmail &email = create PT_MCF_MAIL:MCFOutboundEmail();
&emailsentaddress = "[email protected]";
&plain_text = "Areva China PaySlip";
&email.From = &emailsentaddress;
&email.Subject = &plain_text;
rem Search directory
&payslip_dir = GetEnv("PS_SERVDIR") | "/CHN_PaySlip";
&payslip_dir_all = &payslip_dir | "/*.pdf.exe.zip";

Local PT_MCF_MAIL:MCFBodyPart &text = create PT_MCF_MAIL:MCFBodyPart();
SQLExec("select DESCR from PS_GP_CAL_RUN where CAL_RUN_ID = :1",

TD_GPCN_PSL_AET.CAL_RUN_ID, &CAL_RUN);
rem Email body saved in Explain Text of Message box, which has format.
&text.Text = MsgGetExplainText(25001, 1, "Message Not Found", &CAL_RUN);
&text.ContentType = "text/plain; charset=UTF-8";

rem Search for all files that end with *.pdf.exe and saved files name into array
&FNAMES = FindFiles(&payslip_dir_all, %FilePath_Absolute);
While &FNAMES.Len > 0
  
   rem Pop up file name one by one
   &filedir = &FNAMES.Shift();
   SQLExec("select substr(:1, instr(:1, '/', -1, 1) + 1, length(:1)) from dual",

&filedir, &filename);
   SQLExec("SELECT SUBSTR(:1, 1, length(:1) - 8) FROM DUAL", &filename, &filename_pdf);
   SQLExec("select substr(:1, 1, instr(:1, '_', -1, 1) - 1) from dual", &filename,

&emplid);
   SQLExec("select email_addr from ps_email_addresses where EMPLID = :1 and E_ADDR_TYPE

='BUSN'", &emplid, &emailaddress);
   REM &email.Recipients = &emailaddress;
   rem &email.Recipients = "[email protected]";
   &email.Recipients = "[email protected]";
   Local PT_MCF_MAIL:MCFBodyPart &attach = create PT_MCF_MAIL:MCFBodyPart();
   Local PT_MCF_MAIL:MCFMultipart &mp = create PT_MCF_MAIL:MCFMultipart();
   &attach.SetAttachmentContent(&filedir, %FilePath_Absolute, &filename, "Areva China

PaySlip", "", "");

   rem add email body part
   &mp.AddBodyPart(&text);
   &mp.AddBodyPart(&attach);
   &email.MultiPart = ∓
  
   Local integer &resp = &email.Send();
  
   Evaluate &resp
   When %ObEmail_Delivered
      rem when email was distributed successfully, remove attachment from ftp server
      &server_dir = GetEnv("PS_SERVDIR") | "/CHN_PaySlip/";
      &MyFile = GetFile(&server_dir | &filename, "U", %FilePath_Absolute);
      &MyFile1 = GetFile(&server_dir | &filename_pdf, "U", %FilePath_Absolute);
      &MyFile.Delete();
      &MyFile1.Delete();
      Break;
     
   When %ObEmail_NotDelivered
      rem Check &email.InvalidAddresses, &email.ValidSentAddresses and

&email.ValidUnsentAddresses ;
      &File.WriteLine(&filename | " was not delivered successfully. Please check his/her

email address " | &email.InvalidAddresses);
      Error (1);
      Break;
     
   When %ObEmail_PartiallyDelivered
      rem Check &email.InvalidAddresses, &email.ValidSentAddresses and

&email.ValidUnsentAddresses;
      &File.WriteLine(&filename | " was partially delivered successfully. Please check

his/her email address " | &email.InvalidAddresses);
      Error (1);
      Break;
     
   When %ObEmail_FailedBeforeSending
      rem Get the Message Set Number, message number, Or just get the formatted messages

from &email.ErrorDescription, &email.ErrorDetails;
      &File.WriteLine(&filename | " failed before sending. Please check error descr: " |

&email.ErrorDescription);
      Error (1);
      Break;
   When-Other
      &File.WriteLine(&filename | " failed. Not sure about the reason, Please check email

address or error descr: " | &email.ErrorDescription);
      Error (1);
      Break;
   End-Evaluate;
  
   /*If (&retcode = %Attachment_Success) Then
      &File.WriteLine("DeleteAttachment succeeded");
   End-If;
   If (&retcode = %Attachment_Failed) Then
      &File.WriteLine("DeleteAttachment failed");
   End-If;
   If (&retcode = %Attachment_Cancelled) Then
      &File.WriteLine("DeleteAttachment cancelled");
   End-If;
   If (&retcode = %Attachment_FileTransferFailed) Then
      &File.WriteLine("DeleteAttachment failed: File Transfer did not succeed");
   End-If;
   If (&retcode = %Attachment_FileNotFound) Then
      &File.WriteLine("DeleteAttachment failed: Cannot locate file");
   End-If;*/
  
   /* following error message only in PeopleSoft Internet Architecture */
  
   /*If (&retcode = %Attachment_NoDiskSpaceAppServ) Then
      &File.WriteLine("DeleteAttachment failed: No disk space on the app server");
   End-If;*/
  
   /* following error message only in PeopleSoft Internet Architecture */
  
   /*If (&retcode = %Attachment_NoDiskSpaceWebServ) Then
      &File.WriteLine("DeleteAttachment failed: No disk space on the web server");
   End-If;
  
   If (&retcode = %Attachment_FileExceedsMaxSize) Then
      &File.WriteLine("DeleteAttachment failed: File exceeds the max size");
   End-If;
   If (&retcode = %Attachment_DestSystNotFound) Then
      &File.WriteLine("DeleteAttachment failed: Cannot locate destination system for

ftp");
   End-If;
   If (&retcode = %Attachment_DestSysFailedLogin) Then
      &File.WriteLine("DeleteAttachment failed: Unable to login into destination system

for ftp");
   End-If;*/
  
End-While;

rem remove all files in the directory
rem RemoveDirectory(&payslip_dir, %FilePath_Absolute + %Remove_Subtree);
&File.Close();
/* AREVA T&D – Project – Kevin He - 16/FEB/2009 – End */

 

转载于:https://www.cnblogs.com/GoDevil/archive/2009/05/21/1486409.html

你可能感兴趣的:(PS发送邮件实例!)