Quick way to send emails from PeopleCode

本文介绍了在PeopleCode中发送邮件的两种方式:使用SendMail命令和EmailClass。通过具体的代码示例,展示了如何设置收件人、抄送、密送、主题、正文和附件,以及如何检查邮件发送状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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", "", "");

 

转载于:https://www.cnblogs.com/GoDevil/archive/2009/01/09/1372662.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值