none
mailitem.send stopped working in Word for Outlook 2010 with error 287 RRS feed

  • Question

  • Hi,

    This code is in a Word 2003 doc on Windows 7 SP1 machine with Outlook 2010 SP1. Works fine in Windows XP and Outlook 2003.

    This works until it tries to .send. Then I get the error 287 Application-defined or object-defined error. I think this is to do with outlook security.

    I think this is to do with a security message not appearing allowing users to grant access. This appears in Outlook 2003 but not sure why its not displaying in Outlook 2010, or it could something wrong with the code.

    Private Sub btnSend_Click()

    Dim myOlApp As New Outlook.Application

    Dim myOLItem As Outlook.MailItem

    ActiveDocument.SaveAs mscHomeDrive & "\Meeting.doc"

    Set myOLItem = myOlApp.CreateItem(olMailItem)

    With myOLItem

    .Subject = mscSubject

    .To = mscEmailDestination

    .Attachments.Add (mscHomeDrive & "\Meeting.doc")

    End With

    myOLItem.Display

    myOLItem.Send

    End Sub

     

    Thanks

    JT

    Friday, April 12, 2013 9:11 AM

All replies

  • add call to

    myOlApp.GetNamespace("MAPI")

    just after myOlApp creation

    and change call myOLItem.Display to myOLItem.Display(true)

    Friday, April 12, 2013 10:00 AM
  • Aside from setting a NameSpace object (and logging into it), make sure your security settings are OK. For a login you can use NameSpace.Logon("", "", False, False).
     
    Do you have uptodate anti-virus running on the computer? Make sure your security settings are set to allow code running from external applications with uptodate A-V. See http://technet.microsoft.com/en-us/library/ff657852(v=office.14).aspx for more information.

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "Anonymous543210" <=?utf-8?B?QW5vbnltb3VzNTQzMjEw?=> wrote in message news:46fdfff4-5ceb-46ac-8380-0b6ed4fbeac5...

    Hi,

    This code is in a Word 2003 doc on Windows 7 SP1 machine with Outlook 2010 SP1. Works fine in Windows XP and Outlook 2003.

    This works until it tries to .send. Then I get the error 287 Application-defined or object-defined error. I think this is to do with outlook security.

    I think this is to do with a security message not appearing allowing users to grant access. This appears in Outlook 2003 but not sure why its not displaying in Outlook 2010, or it could something wrong with the code.

    Private Sub btnSend_Click()

    Dim myOlApp As New Outlook.Application

    Dim myOLItem As Outlook.MailItem

    ActiveDocument.SaveAs mscHomeDrive & "\Meeting.doc"

    Set myOLItem = myOlApp.CreateItem(olMailItem)

    With myOLItem

    .Subject = mscSubject

    .To = mscEmailDestination

    .Attachments.Add (mscHomeDrive & "\Meeting.doc")

    End With

    myOLItem.Display

    myOLItem.Send

    End Sub

     

    Thanks

    JT


    Ken Slovak MVP - Outlook
    Friday, April 12, 2013 2:24 PM
    Moderator
  • Thanks both. I have added that code but now it opens the email but doesn't send it.

    I have checked the AV settings in Outlook and though it says there is none it can find, I know Symantec Endpoint Protection is installed. I'll have to check with the administrators and see if they know the settings that covers this.

    Anything else I check?

    Thanks

    JT


    Monday, April 15, 2013 9:28 AM
  • if you changed line myOLItem.Display to myOLItem.Display(true) then sure it is not send untill you actually close inspector window that shows up.
    Monday, April 15, 2013 12:07 PM
  • Is closing the inspector done by the user or in code? If in code what is the command?

    I have changed myOLItem.Display(true) to myOLItem.Display and it still displays the email, but still does not send the message.

    Thanks

    JT

    Monday, April 15, 2013 12:36 PM
  • Hi,

    Have you tried simplified the code?
    i.e. remove the attachment, set a hard-coded smtp address in the To, add Recipients.Resolve, etc.?

    M

    Moshe

    Monday, April 15, 2013 7:51 PM
  • if you just want to send message, remove line for myOLItem.Display completly - what's the point of showing mail if you want to send it right away.

    and show us your current code

    Tuesday, April 16, 2013 4:33 AM
  • I have simplified and changed the address so uses smtp. Add a resolve statement. I now get the 287 error on the resolve line or if I remove this I get the error on the send line. I suspect from what you are saying this should work without issue, so must be down to AV or Outlook settings. I am trying to confirm the AV settings with my administrators as they have hidden them.

    Private Sub btnSend_Click()

    Dim myOlApp As New Outlook.Application

    Dim myOLNamespace As Outlook.NameSpace

    Dim myOLItem As Outlook.MailItem

    Set myOLNamespace = myOlApp.GetNamespace("MAPI")

    myOLNamespace.Logon "", "", False, False

    Set myOLItem = myOlApp.CreateItem(olMailItem)

    With myOLItem

    .Subject = mscSubject

    .To = mscEmailDestination

    .Recipients.Item(0).Resolve

    .Send

    End With

    End Sub

    Tuesday, April 16, 2013 8:51 AM
  • Maybe the login process was not successful?

    What if you try 
    myOLNamespace.Logon "", "", True, False ?

    Or what if you try GetObject (for Outlook.Application) instead of creating new Outlook Application?
    Instead of:
    Dim myOlApp As New Outlook.Application
    Try:
    Dim myOlApp As Outlook.Application
    Set myOlApp = GetObject (,"Outlook.Application")

    Moshe

    Tuesday, April 16, 2013 9:14 AM
  • COM Collections are 1 based, change your

    .Recipients.Item(0).Resolve

    to

    .Recipients.Item(1).Resolve

    Tuesday, April 16, 2013 10:05 AM
  • Thanks all.

    I tried myOLNamespace.Logon "", "", True, False and nothing was displayed and still 287 error on resolve.

    I tried Set myOlApp = GetObject (,"Outlook.Application") and this only works if Outlook is running. When Outlook is running then I get the same error on the resolve statement.

    I changed Recipients.Item(0).Resolve to Recipients.Item(1).Resolve and still get the 287 error.

    Tuesday, April 16, 2013 10:22 AM