none
outlook / vba / Exchange error Error 287, Application-defined or object-defined error RRS feed

  • Question

  • Hi All,

    when running the following code on W7/Outlook 2010 using ISP for email all is good (on all variations of code)

    when on a Exchange / Active-directory site it crashes with the above error when attempting to get the signature of the user.

    I display the item once to get the signature, then continue with setting properties.

    I have tried all sorts of combinations of early/late binding, and creating recipient objects etc and the code always fails somewhere.

    There appears to be problems with interrogating the mailitem or recipient properties. Does one have to use third-party software (Redemption) or does one use different MS libraries/code when on an Exchange-base corporate platform?

    thanks for any input on this.

    Function SendEmail(RecipEmail As String, Subject As String, BBody As String, cc1 As String) As Boolean
      On Error GoTo err_SendEmail
      Dim ErrorLine As Long
      Dim olApp As Outlook.Application
      ErrorLine = 7
      Dim oItem As Outlook.MailItem
      ErrorLine = 9
      Dim tInterval As Integer, signature As String
      SendEmail = False
      Set olApp = CreateObject("Outlook.Application")
      Set oItem = olApp.CreateItem(olMailItem)
      With oItem
          .To = RecipEmail
          .Display   'to get signature for later use
          signature = .Body
          .Subject = Subject
          .Body = BBody & vbCr & vbCr & signature
      End With

      oItem.Display
    .
    .
    .
    End end function


    jamess99

    Monday, January 20, 2014 8:21 PM

All replies

  • Which line of your code exactly causes the exception?

    You do not have to call display the message to retrieve the signature - retrieving the inspector by calling MailItem.GetInspector should be enough.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, January 20, 2014 8:25 PM
  • Hello james99,

    First of all, I have noticed that you call the Display method of the MailItem class twice. There is no need to call the method for getting the Body property.

    Set olApp = CreateObject("Outlook.Application")
    Set oItem = olApp.CreateItem(olMailItem)

    It looks like you are trying to automate Outlook from another application. Be aware that an Outlook security prompt is shown to a user in that case. There are different ways for avoiding or suppressing such warnings. For example, a low level code can be used or a commercial component - Outlook Security Manager. Find all possible options described here.

    Please take a look at the similar forum thread which described the same issue.

    Monday, January 20, 2014 9:02 PM
  • signature = .Body


    jamess99

    Monday, January 20, 2014 10:00 PM
  • I call it twice to get the signature and then append to end of body.

    My question relates to the difference in behaviour on the two platforms, and workarounds


    jamess99

    Monday, January 20, 2014 10:02 PM
  • trying to keep it simple

    My question relates to the difference in behaviour on the two platforms, and workarounds


    jamess99

    Monday, January 20, 2014 10:03 PM
  • Does it work if you use MailItem.GetInspector instead of MailItem.Display?

    Does the error happen immediately or after you process a few items?

    Also note that you will lose all formatting since you are reading and setting the plain text Body rather than HTLBody.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, January 20, 2014 10:03 PM
  • I used to see this security prompt some years ago (which is why we moved to redemption) , but haven't seen it lately. don't get it on either platform.

    jamess99

    Monday, January 20, 2014 10:04 PM
  • Hi james99,

    This is a standard security error. Please take a look at the similar thread which states the following:

    This is the inbuilt security feature.  If we tries to access body of the Appointment, it will throw security dialog.  It can't be avoided, until AddIn dll made trusted.

    You can find all available solutions  here.

    Monday, January 20, 2014 10:08 PM
  • The difference is in the security settings to meet your organization's needs. I'd recommend asking your administrator to adjust the security settings. Please read more about this in the Customizing the Outlook Security Features Administrative Package article.
    Monday, January 20, 2014 10:10 PM
  • The error you get is related to the security prompt. Please take a look at the similar forum thread which described the same issue.
    • Edited by Eugene Astafiev Monday, January 20, 2014 10:12 PM a link is added
    Monday, January 20, 2014 10:11 PM
  • Hi All,

    I think I am getting lost in the discussions. The fact that the code works OK on my dev platform, but fails on the Exchange-based one, is the concern.

    I am attempting to send emails via MS Access, using the above code (instead of Redemption). What do I have to do to make the code work on the Exchange-based platform?

    There is no Add-in, just vba code

    thanks


    jamess99


    • Edited by jamess99 Monday, January 20, 2014 10:14 PM
    Monday, January 20, 2014 10:12 PM
  • The OP asks about about Error 287; what does it have to do with a security prompt (which does not raise an error)?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, January 20, 2014 10:14 PM
  • Is Outlook running at the time your code is executed?

    Would it help if after the line

    Set olApp = CreateObject("Outlook.Application")

    you add something like the following?

    set olNS = olApp.GetNamespace.("MAPI")

    olNS.Logon


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, January 20, 2014 10:15 PM
  • Thanks Dimitry,

    I have tried all the set olNS = olApp.GetNamespace.("MAPI") and olNS.Logon variations. They didn't help, and I believe we don't need to login etc if Outlook is already open?

    Because I was having issues with the code I stripped it down to bare essentials (above). There does appear to be a difference in the way it behaves on the corporate platform so I suspected different libraries running due to Exchange?

    The errors appear to start when using properties like recipients, or getting the body.

    cheers


    jamess99

    P.S. On a different topic. Does anyone know how I can edit my profile email (for this forum) so I can get alerts when responses are in? I cant find the field anywhere and have to go to a meeting.

    • Edited by jamess99 Monday, January 20, 2014 10:34 PM
    Monday, January 20, 2014 10:26 PM
  • It is safer to have Namespace.Logon - it will ensure Outlook has a valid MAPI session if it not already running. If it is running, the call will do nothing.

    How reproducible is the eerror?

    Does happen all the time or only occasionally?

    As for the notification, by default an email will be sent to the address you used to log to the forums.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Monday, January 20, 2014 10:38 PM
  • The error is 100% reproducible (and always happens) on the exchange-based platform, and 0% on ISP mail server.

    I have added a work-around (for signature): I store the signature in the database with the email address, and append to the body. adding cc's isn't working because I cannot create a recipient object on this platform (to add cc's and change type to olCC), but I can append all reci9pients to the primary 'to' so we are still afloat.

    It is strange that the Outlook warning messages don't appear, but that is OK because the client wont permit Redemption and we need to send multiple emails in a batch.

    Re my account: I don't get emails, and couldn't find where to view/change the existing one.

    thanks for all your input.


    jamess99

    Tuesday, January 21, 2014 1:03 AM
  • Dmitry,

    Sometimes the security prompt is not shown in Outlook. Please take a look at the similar forum thread - Error 287 in Outlook 2003 VBA script but no security popup to answer .                    

    Tuesday, January 21, 2014 7:45 AM
  • james99,

    Did you have a chance to look at the Error 287 in Outlook 2003 VBA script but no security popup to answer forum thread I mentioned in the initial post there?

    Tuesday, January 21, 2014 7:46 AM
  • Thanks Dmitry,

    I have asked someone at the client's site to check these settings - if this is the problem I'll let you know.

    cheers


    jamess99

    Tuesday, January 21, 2014 4:24 PM
  • You are always welcome! :)

    Tuesday, January 21, 2014 5:40 PM
  • Hi Eugene

    Assuming the security settings are causing the line ' signature = .Body' to fail (still waiting for client but looks probable), why would it not fail on the line above and below (or anywhere else?)?

    The client doesn't want to use 3rd-party (Redemption) software, or change their security model, and I believe the CDO route would not leave items in the Sent folder (for future ref.).

    Would you concur the solution (above, with signature stored in db and appended via code) is 'as good as it gets'?

    cheers


    jamess99

    Tuesday, January 21, 2014 5:54 PM
  • Hmmm... I don't think I have ever seen the security patch causing error like that.

    I'd be curious to see if the same error is raised when a ssecured property is accessed (Body, SenderEmailAddress, To, CC, etc.), but not the unsecured properties (Subject, MessageClass, etc.).


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Tuesday, January 21, 2014 8:39 PM
  • Please be aware that you will get a security prompt if you try to send an e-mail programmatically (not just accessing a property). For example, calling the Send method of the MailItem class will bring a security message. So, if you are going to send e-mails in the background I'd recommend using any tool for suppressing such warnings.

    As I wrote above, you can find all possible solutions described on the Outlook "Object Model Guard" Security Issues for Developers page. 

    Wednesday, January 22, 2014 2:30 PM
  • The error is thrown when trying to access the Body property, not unsecured properties. 
    Wednesday, January 22, 2014 2:33 PM