Search This Blog

Monday, June 10, 2013

Sending multiple attachments through mail from App Engine

The below code will send multiple attachments through the mail.

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)
&File_name_path2 = Place the full path ( like /...../filename2.pdf')
&file_name_email2 = Name of the attached filename (filename2.pdf)


Local PT_MCF_MAIL:MCFBodyPart &attach1 = create PT_MCF_MAIL:MCFBodyPart();
Local PT_MCF_MAIL:MCFBodyPart &attach2 = create PT_MCF_MAIL:MCFBodyPart();

&attach1.SetAttachmentContent(&File_name_path, %FilePath_Absolute, &file_name_email, "Report Description", "", "");
&attach2.SetAttachmentContent(&File_name_path2, %FilePath_Absolute, &file_name_email2, "Report Description 2 ", "", "");

Local PT_MCF_MAIL:MCFMultipart &mp = create PT_MCF_MAIL:MCFMultipart();
&mp.AddBodyPart(&text);
&mp.AddBodyPart(&attach1);
&mp.AddBodyPart(&attach2);
&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: