Saturday, June 6, 2020

Send Mail with attachment

Today we gonna see how to send mail with multiple attachments:
Let's get Started:

Step 1:Create the page for getting an emaild.
Step 2:Create the button in which we will write the code for sending the mail.
Step 3:Write code on Button.FieldChange event.
 
import PT_MCF_MAIL:*;
 
Local PT_MCF_MAIL:MCFOutboundEmail &eMail;
&eMail = create PT_MCF_MAIL:MCFOutboundEmail();
 
/* Define mandatory fields */
&eMail.From = example@server.com;
&eMail.Recipients = example1@server.com;
&eMail.Subject = "TEST";
 
 
/* Create a body part for the text attachment */
 
Local PT_MCF_MAIL:MCFBodyPart &attachment1;

&attachment = create PT_MCF_MAIL:MCFBodyPart();

&attachment.Text="<html><body>Hi<br><br>This is test mail<br><br>Thanks and
 Regards,<br>Example<br>";
 
 

&attachment.ContentType="text/html";
 
/* Create a body part for file attachment  */
 
Local PT_MCF_MAIL:MCFBodyPart &attachment2;
&attachment1 = create PT_MCF_MAIL:MCFBodyPart();
 
/* can put your network or server address instead of "0.0.0.0" and your drive
and file name.*/
 
&attachment1.SetAttachmentContent("0.0.0.0\d\Example\test.text",
%FilePath_Absolute,"test.txt", "Test File", "", "");
 
/* Create a body part for image attachment  */
 
Local PT_MCF_MAIL:MCFBodyPart &attachment3;
&attachment2 = create PT_MCF_MAIL:MCFBodyPart();
&attachment2.SetAttachmentContent(("0.0.0.0\d\Example\test.jpg",
%FilePath_Absolute,"test.jpg", "Test Image", "", "");
 
/* Attach the body parts to the main email message */
 
Local PT_MCF_MAIL:MCFMultipart &mp;
&mp = create PT_MCF_MAIL:MCFMultipart();
&mp.AddBodyPart(&attachment1);
&mp.AddBodyPart(&attachment2);
&mp.AddBodyPart(&attachment3);
&eMail.MultiPart = &mp;
 
/* Send the email */
&result = &eMail.Send();
 

Evaluate &result

   When %ObEmail_Delivered
      &done = True;
      Break;
       
   When %ObEmail_NotDelivered
           &done = False;
           Break;
   When %ObEmail_PartiallyDelivered
          &done = False;
          Break;
   When %ObEmail_FailedBeforeSending
      &done = False;
      Break;
End-Evaluate;

 
NOTE: If your file or image is on server you can use network(0.0.0.0)
and this example the file is stored in d drive. Hence,the path is
0.0.0.0\d\Example\test.txt

 

No comments:

Post a Comment

How to create pagelet and quicklinks in peoplesoft

  Step 1: Go to PeopleTools->Portal->Portal Utilities->Navigation Collection (for selecting the navigation link for the pagelet ...