Send Emails from PeopleCode (SendMail Function)

Your rating: None Average: 4.3 (8 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 42 weeks 3 days 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 42 weeks 3 days 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 4 weeks 3 days ago. Offline
Joined: 03/26/2008
Posts: 208
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 2 years 38 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.

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
The question below is to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.