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 = "T&D_HRIS_ADMINISTRATOR@areva-td.com";
&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 = "max.an@areva-td.com";
   &email.Recipients = "khe@ataway.com";
   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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值