1. GH kumar
  2. PowerBuilder
  3. Thursday, 12 April 2018 06:24 AM UTC
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
Roland Smith Accepted Answer Pending Moderation
  1. Thursday, 12 April 2018 14:25 PM UTC
  2. PowerBuilder
  3. # 1

You have too much inside the loop. Try doing it like this:

SetSMTPServer
SetUserNamePassword
SetPort
SetAuthMethod
SetConnectionType
SetCharSet
SetSenderEmail
SetSubject
SetMessage

SmtpConnect

​for loop
     SetRecipientEmail
     SmtpSend
next

SmtpDisconnect

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Thursday, 12 April 2018 14:32 PM UTC
  2. PowerBuilder
  3. # 2

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.

 

Comment
  1. GH kumar
  2. Friday, 13 April 2018 06:12 AM UTC
sir, 



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

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.