Search This Blog

Sunday, June 9, 2013

Sending mail through App Engine program

Below code sends mail through App engine program.  The code uses the PT_MCF_MAIL package to send mail with attachment.

AE Peoplecode:

import PT_MCF_MAIL:*; // Inlcude the App package

/**** Send Mail ****/

Local PT_MCF_MAIL:MCFOutboundEmail &email = create PT_MCF_MAIL:MCFOutboundEmail();

&email.From = ""; // when set to null, the email configured at server level will send mail

SQLExec("select URL from psurldefn where url_id = "URLid which stores the recipients list", &Email_To);
&email.Recipients = &Email_To;

&email.Subject = Place the Subject of the mail here;

Local string &plain_text = "Report Description";
Local PT_MCF_MAIL:MCFBodyPart &text = create PT_MCF_MAIL:MCFBodyPart();
&text.Text = &plain_text;

&File_name_path = Place the full path ( like /...../filename.pdf')
&file_name_email = Name of the attached filename (filename.pdf)

Local PT_MCF_MAIL:MCFBodyPart &attach1 = create PT_MCF_MAIL:MCFBodyPart();
&attach1.SetAttachmentContent(&File_name_path, %FilePath_Absolute, &file_name_email, "Report Description", "", "");

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

Local integer &res = &email.Send();

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;

No comments: