Send Emails from PeopleCode (SendMail Function)

Your rating: None Average: 3.9 (23 votes)

You can use the SendMail PeopleCode function to send emails from within PeopleCode. You can also call this function from an Application Engine.

Note: Make sure your SMTP server is configured properly or the SendMail function will fail.

Local string &MAIL_CC, &MAIL_TO, &MAIL_BCC, &MAIL_SUBJECT, &MAIL_TITLES, &MAIL_TEXT, &MAIL_FILES, &MAIL_FROM, &REPLYTO, &SENDER;
Local number &MAIL_FLAGS;

&MAIL_FLAGS = 0;
&MAIL_TO = "email-address-message-going-to";
&MAIL_CC = "";
&MAIL_BCC = "";
&MAIL_SUBJECT = "Test email";
&MAIL_TEXT = "Sending an email from PeopleCode.";
&MAIL_FILES = "";
&MAIL_TITLES = "";
&MAIL_FROM = "email-address-message-is-from";
&MAIL_SEP = ";";
&CONTTYPE = "";
&REPLYTO = "";
&SENDER = "";

&RET = SendMail(&MAIL_FLAGS, &MAIL_TO, &MAIL_CC, &MAIL_BCC, &MAIL_SUBJECT, &MAIL_TEXT, &MAIL_FILES, &MAIL_TITLES, &MAIL_FROM, &MAIL_SEP, &CONTTYPE, &REPLYTO, &SENDER);

If &RET <> 0 Then
 MessageBox(0, "", 0, 0, "Return code from SendMail= " | &RET);
 /*Do error processing here*/
End-If;

Please try to help out with unanswered topics on the forum. Chances are you have had the same issue/question some time in your IT career!

Comments

Have a question? Please ask it on the forum instead.
prasanna's picture
prasanna (not verified)
Re: Send Emails from PeopleCode (SendMail Function)

Failed to connect to the SMTP server at :25 (80,1)
Message Set Number: 80
Message Number: 1
Message Reason: Failed to connect to the SMTP server at :25 (80,1)
Application Engine program BIS_MAIL ended normally
i am getting this error when i run this program in App Engine. Can you pls help me how to resolve this.

CompShack's picture
User offline. Last seen 3 years 51 weeks ago. Offline
Joined: 12/09/2007
Posts: 167
Re: Send Emails from PeopleCode (SendMail Function)

Is your SMTP server configured properly? Try sending emails manually, follow this post.

I would also comment your variables in your application engine and try hard coding your values, like email address, cc, subject and so on. At this point, you just want to test the sendmail function and not your application engine.

Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog

Shannon's picture
Shannon (not verified)
Re: Send Emails from PeopleCode (SendMail Function)

I am working on a application that when employee submit a leave request, the superviser receives a e-mail alert.
1) What peoplecode on the Submit button? How to write?
2) How do I generically put supervisor's e-mail?
Please help.
Thanks!
Shannon

CompShack's picture
User offline. Last seen 3 years 51 weeks ago. Offline
Joined: 12/09/2007
Posts: 167
Re: Send Emails from PeopleCode (SendMail Function)

You can still use the same SendMail function to send your emial. Your PeopleCode will have an SQLExec function to get the supervisor email address.

SELECT emailid
  FROM psoprdefn
 WHERE oprid = (SELECT supervisor_id
  FROM ps_employees
 WHERE emplid = 'user-id-submitting-request');

You have all the info you need at this point, so just write your peoplecode to do the work.

n/a
Shannon's picture
Shannon (not verified)
Re: Send Emails from PeopleCode (SendMail Function)

Thanks for your help! 1) What peoplecode on the Submit button? How to write? SavePreChange?

Akshata's picture
Akshata (not verified)
Re: Send Emails from PeopleCode (SendMail Function)

I am getting this same error
Failed to connect to the SMTP server at :25 (80,1)]
on using the sendmail function

On using the peopelsoft delivered Notify, I dont get this error but the mail is also not delivered.

Please advise

Ashar's picture
User offline. Last seen 2 years 30 weeks ago. Offline
Joined: 03/26/2008
Posts: 227
Re: Send Emails from PeopleCode (SendMail Function)

is the smtp server up n properly configured for the system? any of the other notifications are working?
if not check with your ps admin.

iammanku's picture
User offline. Last seen 9 years 19 weeks ago. Offline
Joined: 03/24/2009
Posts: 10
Re: Send Emails from PeopleCode (SendMail Function)

In your peopleCode where sendmail fails, do you try to attach any URL to the email text?

If you use functions like GenerateComponentPortalURL inside your App Engine peoplecode, then there s chance for this to fail!

Guest's picture
Guest (not verified)
Re: Send Emails from PeopleCode (SendMail Function)

hi,

i need to send mail using app engine program but i want to us one table in Mail content.
can any body help me to find solution?

thanks in advance :-)

Harsha Bhasuthkar's picture
Harsha Bhasuthkar (not verified)
Re: Send Emails from PeopleCode (SendMail Function)

Hi ALL,

To fix the below error "Failed to connect to the SMTP server at :25 ", check the SMTP configuration is done in Process Schedular.

Mail Notification works fine, if SMTP is configured in App Server.
Mail Notification from Sendmail function (PeopleCode / App Engine) will not work when SMTP is not configured in Process Scheduler.

Regards,
Harsha
email:

rahul tagra's picture
rahul tagra (not verified)
Re: Send Emails from PeopleCode (SendMail Function)

I want to send mail at the submit button click with some attachment.

mail is going but the attachment is not.

the same code tried in app engine sends the attachment.
is thee some difference in restriction in sendmail function regarding its application engine or the peoplecode we are using it in ?

any help in this regard would be great.

thanks in advance !!!

Ashish's picture
Ashish (not verified)
Re: Send Emails from PeopleCode (SendMail Function)

try to run the same application Engine from front End.

vijayalakshmi's picture
User offline. Last seen 6 years 4 weeks ago. Offline
Joined: 05/08/2012
Posts: 9
Re: Send Emails from PeopleCode (SendMail Function)

hi all,

Local string &MAIL_CC, &MAIL_TO, &MAIL_BCC, &MAIL_SUBJECT, &MAIL_TITLES, &MAIL_TEXT, &MAIL_FILES, &MAIL_FROM, &REPLYTO, &SENDER;
Local number &MAIL_FLAGS;

&MAIL_FLAGS = 0;

rem &MAIL_TO = LNT_DERIVED_SKL.EMAILID.Value;
&MAIL_TO = "Ankita.Singh@lntinfotech.com";
&MAIL_CC = "Vjayalakshmi.Munishami@lntinfotech.com";
&MAIL_BCC = "";
&MAIL_SUBJECT = "Your 1 Skill has been approved";
/*
&MAIL_TEXT1 = LNT_DERIVED_SKL.EMAILTEXT.Value;
&MAIL_TEXT2 = LNT_DERIVED_SKL.EMAILTEXT.Value;
*/
rem &MAIL_TEXT = LNT_DERIVED_SKL.EMAILTEXT.Value;
&MAIL_TEXT = " your skill has been approved";
&MAIL_FILES = "";
&MAIL_TITLES = "";
&MAIL_FROM = "Supriya.Kunnath@lntinfotech.com";
&MAIL_SEP = ";";
&CONTTYPE = "";
&REPLYTO = "";
&SENDER = "Vijayalakshmi.Munishami@lntinfotech.com";

&RET = SendMail(&MAIL_FLAGS, &MAIL_TO, &MAIL_CC, &MAIL_BCC, &MAIL_SUBJECT, &MAIL_TEXT, &MAIL_FILES, &MAIL_TITLES, &MAIL_FROM, &MAIL_SEP, &CONTTYPE, &REPLYTO, &SENDER);

WinMessage("sent mail to value is : " | &RET);

If Not (&RET = 0) Then
rem MessageBox(0, "", 0, 0, "Return code from SendMail= " | &RET);
WinMessage("mail sent is not sucess: " | &RET);
End-If;

this code am using to send mail , in component level workflow event.
its returns value is 0 but mail is nit getting sent.
and all other notifications are sent . and smtp an app server and process schudler is working fine.
can any one help me in this. pls.
its urgent.

Ashar's picture
User offline. Last seen 2 years 30 weeks ago. Offline
Joined: 03/26/2008
Posts: 227
Re: Send Emails from PeopleCode (SendMail Function)

What does smtp log show?

Aravind's picture
Aravind (not verified)
Re: Send Emails from PeopleCode (SendMail Function)

Hi,

But I want to send the output of the xml publisher report which is a PDF format as an attchment to the mail.What are the modifications,I need to do?????

Guest's picture
Guest
Re: Send Emails from PeopleCode (SendMail Function)

hello! we are generating emails via Send Mail funtionality, it works fine however there is one email that outputs an error saying

"Return Code from Mail = 8".

Has anyone of you experience this? or has an idea what does the error means?

Thanks!

Guest's picture
Guest
Re: Send Emails from PeopleCode (SendMail Function)

check the smtp log for error details

Guest's picture
Guest
Re: Send Emails from PeopleCode (SendMail Function)

Hello, I have a question.
I want to change the "sender" in the email, so that instead of an email address it displays a NAME. Has any one done this before?

The code that i am using is as below

Local string &flag;
Local string &studentid;
Local string &emailid;

&studentid = XX_ST_EMAIL_TBL.EMPLID;
&PREF_EMAIL_FLAG = "Y";

If (XX_ST_EMAIL_VW.EMAIL_ADDR <> "") Then
If (XX_ST_EMAIL_TBL.COMM_COMMENTS = "") Then
WinMessage("Cannot send a blank email");
End-If;
If (XX_ST_EMAIL_TBL.COMM_COMMENTS <> "") Then
XX_ST_EMAIL_TBL.FLAG = "Y";
If XX_ST_EMAIL_TBL.FLAG = "Y" Then
XX_EMAIL_BT_WRK.SEND_TO_AP.Enabled = False;
End-If;

/*code start*/
SQLExec("Select EMAIL_ADDR from PS_EMAIL_ADDRESSES WHERE PREF_EMAIL_FLAG=:1 AND EMPLID=:2 ", &PREF_EMAIL_FLAG, &studentid, &emailid);
If All(&emailid) Then
Local PT_MCF_MAIL:MCFOutboundEmail &email = create PT_MCF_MAIL:MCFOutboundEmail();
&email.SMTPServer = "172.16.207.11";
&email.SMTPPort = 25;
&ToList = &emailid;
&FromList = "GROUP_NOTIFICATION";/*This statement is used to changed the sender name. But it is not working*/
&ReplyToList = "abc@xyz.com";
&Subject = "Student Notification";
&email.Recipients = &ToList;
&email.From = &FromList;
&email.ReplyTo = &ReplyToList;
&email.Subject = &Subject;

&enter = Char(13);
&space = Char(9);

Local string &plain_text = XX_ST_EMAIL_TBL.COMM_COMMENTS;
Local PT_MCF_MAIL:MCFBodyPart &text = create PT_MCF_MAIL:MCFBodyPart();
&text.Text = &plain_text;

Local PT_MCF_MAIL:MCFBodyPart &attach = create PT_MCF_MAIL:MCFBodyPart();

Local PT_MCF_MAIL:MCFMultipart &mp = create PT_MCF_MAIL:MCFMultipart();
&mp.AddBodyPart(&text);

&email.MultiPart = ∓

Local integer &resp = &email.Send();
WinMessage(&resp);
Local boolean &done;
Evaluate &resp
When %ObEmail_Delivered
&done = True;
MessageBox(0, "", 0, 0, "Email was Sucessfully sent");
Break;
When %ObEmail_NotDelivered
&done = False;
MessageBox(0, "", 0, 0, "Email Sending failed");
Break;
When %ObEmail_PartiallyDelivered
&done = False;
MessageBox(0, "", 0, 0, "email partially" | &email.ValidUnsentAddresses);
Break;

End-Evaluate;
DoSave();

End-If
/*code end*/

End-If;

End-If;

Guest's picture
Guest
Re: Send Emails from PeopleCode (SendMail Function)

Lepa:

Thanks for the concise and accurate explanation of how to use sendmail in PeopleCode. I was particularly interested in how to use "Reply-to". This saved me quite a bit of time!

Thanks again.

Frank Staheli
Brigham Young University

Guest's picture
Guest
Re: Send Emails using SendMail Function in Application Engine

hello! we are generating emails via Send Mail functionality, it works fine with Page but when i use Send mail function in application engine, Process continuous goes in Processing Status for undefined time.

Has anyone know how to resolve this?

Thanks!

Guest's picture
Guest
Re: Send Emails from PeopleCode (SendMail Function)

Please read the answers before responding with another question. Several times the answer has been provided.

Guest's picture
Guest
Re: Send Emails from PeopleCode (SendMail Function)

Can you please share the code which you have used to send mail along with the attachment.

Post new comment

CAPTCHA
The question below is to prevent automated spam submissions.
1 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.