Creating an Email with Attachments
The following code example creates an email with two attachments.
Oracle recommends that you always provide the proper extension in the file name, otherwise the receiving email client may not be able to associate it with the appropriate application.
Note:
There is no automatic restriction of attachment size using the mail classes. To restrict an email based on attachment size, your application must check the size of an attachment before composing and sending the email.
import PT_MCF_MAIL:*;
Local PT_MCF_MAIL:MCFOutboundEmail &email =
create PT_MCF_MAIL:MCFOutboundEmail();
&email.From = &FromAddress;
&email.Recipients = &ToList;
&email.Subject = &Subject;
Local string &plain_text = "Hi there!";
Local PT_MCF_MAIL:MCFBodyPart &text = create PT_MCF_MAIL:MCFBodyPart();
&text.Text = &plain_text;
Local PT_MCF_MAIL:MCFBodyPart &attach1 = create PT_MCF_MAIL:MCFBodyPart();
&attach1.SetAttachmentContent("Ocean Wave.jpg", %FilePath_Relative,
"Ocean Wave.jpg", "Ocean Wave", "", "");
/* %FilePath_Relative indicates the file is available at Appserver's FILES⇒
dierctory */
Local PT_MCF_MAIL:MCFBodyPart &attach2 = create PT_MCF_MAIL:MCFBodyPart();
&attach2.SetAttachmentContent("///file:C:/User/Documentum/XML%20Applications⇒
/proddoc/peoplebook_upc/peoplebook_upc.dtd",
%FilePath_Absolute, "Sample.jpg", "Sample", "", "");
/* The Sample.jpg is available in the "public" folder of my-server machine*/
Local PT_MCF_MAIL:MCFMultipart &mp = create PT_MCF_MAIL:MCFMultipart();
&mp.AddBodyPart(&text);
&mp.AddBodyPart(&attach1);
&mp.AddBodyPart(&attach2);
&email.MultiPart = ∓
Local integer &res = &email.Send();
Local boolean &done;
Evaluate &resp
When %ObEmail_Delivered
/* every thing ok */
&done = True;
Break;
When %ObEmail_NotDelivered
&done = False;
MessageBox(0, "", &email.MessageSetNumber, &email.MessageNumber, "PeopleTools error not found", &email.GetErrorMsgParam(1), &email.GetErrorMsgParam(2));
Break;
When %ObEmail_PartiallyDelivered
&done = True;
Break;
When %ObEmail_FailedBeforeSending
&done = False;
MessageBox(0, "", &email.MessageSetNumber, &email.MessageNumber, "PeopleTools error not found", &email.GetErrorMsgParam(1), &email.GetErrorMsgParam(2));
Break;
End-Evaluate;