Roland smith email code attachment issue

1
0
-1
Roland sir,
i tested your send email code (pbnismtp.pbl file) and it works perfectly. i want to send bulk emails with attachments. So in bulk email tab window(u_tabpg_bulk) i add a listbox and add and delete button to add files to the attachment .
as per the u_tabpg_smtp code  i add following code to send email button of u_tabpg_bulk
// build attachment list
li_max = lb_attachments.TotalItems()
For li_idx = 1 To li_max
ln_smtp.AddToString(ls_attach, lb_attachments.Text(li_idx))
Next
and also add the below code to the send the email section below
// send the emails
For li_idx = 1 To li_max
 try
  // set message properties
  ln_smtp.SetSenderEmail(ls_sender)
  ln_smtp.SetRecipientEmail(ls_recipients[li_idx])
  ln_smtp.SetSubject(ls_subject)
  ln_smtp.SetMessage(ls_body, lb_html)
  If ls_attach <> "" Then
      ln_smtp.SetAttachment(ls_attach)
  End If
   
  // send the email
  li_rc = ln_smtp.SmtpSend()
  catch ( NullObjectError noe2 )
  MessageBox("SmtpSend: Null Object Exception", &
      noe2.getMessage(), StopSign!)
 catch ( PBXRuntimeError pbxre2 )
  MessageBox("SmtpSend: PBX Exception", &
      pbxre2.getMessage(), StopSign!)
 catch ( Throwable oe2 )
  MessageBox("SmtpSend: Other Exception", &
      oe2.getMessage(), StopSign!)
 finally
  If li_rc = 1 Then
   // Success
                  Else
   ls_errmsg = ln_smtp.GetLastErrorMessage()
   MessageBox("SmtpConnect Error: " + String(li_rc), &
       ls_errmsg, StopSign!)
   Exit // Break out of loop
  End If
 end try
 Next
it compile succesfully but when i run and attach a file and click send Email button
i got a error messge box of  smtpconnect.pbx exception
error calling method of a pbni object
when ic lick ok button then i get
powerbuilder application execution error(R0000)
error: error calling method of a pbni object
i tried  li_rc = ln_smtp.Send() instead of li_rc = ln_smtp.SmtpSend()
but still error occurs, if i send without attachments it send successfully
sir, can you explain where i am wrong and how to send attachments in bulk email program?
i am using pb 12.5 classic and 32 bit applications
regards
kumar

Question Tags: 

Answers

Roland Smith answered Roland smith email code attachment issue

1
-1
-1

Sorry, I forgot the SetAttachment in my example and this forum doesn't allow editing posts or even seeing the post you are responding to.

Add SetAttachment as the last call before the SmtpConnect.

 

ghkumarchd_28597's picture

sir, 

many thanks for the response, now it is working and send the attachment successfully