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

Accepted Answer
Christopher Craft Accepted Answer Pending Moderation
  1. Tuesday, 30 April 2024 23:26 PM UTC
  2. PowerBuilder
  3. # Permalink

For those that might ever run into this - This user had a Contact setup but there were no email addresses in 'Email', 'Email 2' or 'Email 3' section.  Instead, they had Email addresses in the 'Notes' section of the Contact.  This seems to do interesting things because Outlook will find these entries and see them as a 'contact' but when going through OLE it just raised the error.  As soon as I had the customer add the Email address to the Email field then everything started working.

Now, that being said...I am unable to re-create this in-house which is really annoying!  I created a contact just like theirs (or I thought) but I do not get the error when attempting to use it.   I have tried multiple iterations and cannot get it to error.  So, even though I have a 'fix' I am unable to determine the root cause so if anyone else happens to find it I would really appreciate it if you post it back here!

Thanks again,

Chris Craft

Comment
  1. Arnd Schmidt
  2. Wednesday, 1 May 2024 19:53 PM UTC
Hi Christoper,

why are you not using a try catch for an OLERuntimeError Exception?

regards

Arnd

  1. Helpful
  1. Christopher Craft
  2. Thursday, 2 May 2024 15:48 PM UTC
I probably should be. I will add that catch but are you thinking I might get a better error description using OLERuntimeError?
  1. Helpful
There are no comments made yet.


There are replies in this question but you are not allowed to view the replies from this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.