Sending Multiple attachment using MCF Send mail method
Below is the sample code to send multiple attachment in mail using MCF Send() mail method.
Local any &FromURL = "record://PV_ATT_DB_SRV/"; Local string &FILENAME; Local Rowset &rwln1 = CreateRowset(Record.PV_ATTACHMENTS); Local SQL &Sql1 = CreateSQL("select attachsysfilename from PS_PV_ATTACHMENTS a,ps_SPF_RESUME_ATT b where a.scm_attach_id=b.scm_attach_id and b.person_id=:1", "000000000000025", &FILENAME); While &Sql1.Fetch(&FILENAME) &attach = create PT_MCF_MAIL:MCFBodyPart(); Local string &ToFile = "C:/user/" | &FILENAME; Local any &errorCode = GetAttachment(&FromURL, &FILENAME, &ToFile); If &i = 1 Then &multiattach = CreateArray(&attach); &multiattach [&i] = &attach; Else &multiattach [&i] = &attach; End-If; &multiattach [&i].SetAttachmentContent(&ToFile, %FilePath_Absolute, &FILENAME, " ", "", ""); &mp.AddBodyPart(&multiattach [&i]); End-While; Local PT_MCF_MAIL:MCFBodyPart &test1 = create PT_MCF_MAIL:MCFBodyPart(); Local PT_MCF_MAIL:MCFBodyPart &eMail1 = create PT_MCF_MAIL:MCFBodyPart(); &eMail1.Text = &Message; &mp.AddBodyPart(&eMail1); &eMail.MultiPart = ∓ &res = &eMail.Send(); Local boolean &done; Evaluate &res When %ObEmail_Delivered /* every thing ok */ &done = True; MessageBox(0, "", 0, 0, "Email Sent Successfully"); Break; When %ObEmail_NotDelivered /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* Check &email.InvalidAddresses, &email.ValidSentAddresses */ /* and &email.ValidUnsentAddresses */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ &done = False; MessageBox(0, "", 0, 0, "Email Not delivered" | &eMail.InvalidAddresses | &eMail.ValidSentAddresses | &eMail.ValidUnsentAddresses); Break; When %ObEmail_PartiallyDelivered /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* Check &email.InvalidAddresses, &email.ValidSentAddresses */ /* and &email.ValidUnsentAddresses */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ &done = True; MessageBox(0, "", 0, 0, "Email Partially delivered" | &eMail.InvalidAddresses | &eMail.ValidSentAddresses | &eMail.ValidUnsentAddresses); Break; When %ObEmail_FailedBeforeSending /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ /* Get the Message Set Number, message number; */ /* Or just get the formatted messages from */ /* &email.ErrorDescription, email.ErrorDetails; */ /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */ &done = False; MessageBox(0, "", 0, 0, "Email Failed Before Sending" | &eMail.ErrorDescription | &eMail.ErrorDetails); Break; End-Evaluate; If &done = True Then While &Sql1.Fetch(&FILENAME) Local string &deleteFile = "C:/user/" | &FILENAME; Local JavaObject &f = CreateJavaObject("java.io.File", &deleteFile); &f.delete(); End-While; End-If;
Note: This is sample code. This required to include necessary application package and to declare objects.
Comments
Post a Comment