1. Christopher Craft
  2. PowerBuilder
  3. Tuesday, 16 April 2024 21:58 PM UTC

PB 2022 1900

We recently changed our Emailing from MAPI to use Outlook OLE instead.  This has been working great but every so often we get a customer calling in reporting a throwable error during the send operation ("Error accessing external object property send").  This error would make me think that the Send is not defined in the OLE Item but the odd part is it only happens for certain emails.  If they change the email address and try again then it works. I thought maybe Outlook was choking on the email address but I ran a test on my machine with that same email and it worked.

I have no idea what could be happening here.  Does anyone know how I can debug something like this?  I have included a code snippet so you can see what it is doing. The error occurs at ole_item.Send below.

Thank you,

Chris Craft

Code:

OLEObject ole_outlook
OLEObject ole_item, ole_attach

TRY

//CONNECT
ole_outlook = CREATE OLEObject
liSession = ole_outlook.ConnectToObject("","outlook.application")

// Create OLE Item
ole_item = ole_outlook.CreateItem(0)

// Address it.
ole_item.To = isCommString
ole_item.Subject = isSubjectText

// Attachment
int i, iMax
iMax = GetAttachmentCount()
IF iMax > 0 THEN
   ole_attach = ole_item.Attachments
   FOR i = 1 TO iMax
      lsAttachment = GetAttachmentName(i)
      IF lsAttachment <> "" AND NOT IsNULL(lsAttachment) THEN
         ole_attach.add(lsAttachment)
      END IF
   NEXT
END IF

// Body
ole_item.BodyFormat = 1 // Plain Text
ole_item.Body = lsViewerText

// Send the Email
ole_item.Send //sends the message

CATCH ( NullObjectError noe )
   liRet = -1
   lsDetails = noe.getMessage()
   lsMsg = 'Outlook Null Object Error'

CATCH ( PBXRuntimeError pbxre )
   liRet = -1
   lsDetails = pbxre.getMessage()
   lsMsg = 'Outlook Runtime Error'
CATCH ( Throwable oe )
   liRet = -1
   lsDetails = oe.getMessage()
   lsMsg = 'Outlook Throwable Error'
FINALLY
   // Cleanup
   IF IsValid(ole_outlook) THEN
      ole_outlook.DisconnectObject()
   END IF
   DESTROY ole_item
   DESTROY ole_outlook
END TRY

Who is viewing this page


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