Outlook Integration

Anyone know how to read/write to Outlook locally?

It seems that

dim app as new OLEObject( "Outlook.Application" )

is no longer supported and fails with “Invalid class string”.

This Code works like a charm here on Windows 10 using Outlook 2019.

Public Sub SendMail_Outlook(psTo As String, psFrom As String, psSubject As String, psContent As String, Optional psAttachments() As String)
  #Pragma Unused psAttachments
  #Pragma Unused psFrom
  
  Dim bOK As Boolean
  
  Try
    
    Dim obj As OLEObject
    Dim newmail As OLEObject
    Dim v As Variant
    obj = New OLEObject("Outlook.Application", True)
    
    If (obj <> Nil) Then
      v = obj.CreateItem(0)
      If v.objectvalue IsA OLEObject Then
        newmail = OLEObject(v.objectValue)
        newmail.Value("To") = psTo
        // newMail.Value("Sender") = psFrom
        newmail.Value("Subject") = psSubject
        newmail.Value("Body") = psContent
        Try
          If psAttachments <> Nil Then
            If (psAttachments.LastIndex >= 0) Then
              Dim attachments As OLEObject
              attachments = newmail.Invoke("Attachments")
              If (attachments <> Nil) Then
                For i As Integer = 0 To psAttachments.LastIndex
                  Dim sParams(1) As Variant
                  sParams(1) = psAttachments(i)
                  attachments.Invoke("Add", sParams)
                Next
              End If
            End If
          End If
        Catch err As RuntimeException
          
          
        End Try
        
        Try
          
          v = newmail.Invoke("Display")
          bOK = True
          
        Catch err As RuntimeException
          
          bOK = False
          
        End Try
        
      End If
      
    End If
    
  Catch err As RuntimeException
    
    bOK = False
    
  End Try
  
  If bOK Then Return 'Opened in Win-Outlook
End Sub

BTW: I stripped many things out and added some other to make it work again, for this Post. Please excuse the mess. :wink:

PS: If i remember this Code is based on an example found on: OLEObject — Xojo documentation

Is Outlook definitely installed on this system? :thinking:

Along these same lines:

I often find that OLE registration for Outlook breaks on Windows, and causes these errors. If Outlook IS definitely installed, try doing a “Quick Repair” on MS Office from Windows Apps & Features. This should fix the OLE registration (if that’s what’s causing this).

2 Likes

Thanks for the example code. I tried it and got the same ‘Invalid class string’.

Windows 10
Outlook 1.2024.103.100 (new, free version)
Xojo 2023r4

Outlook installed and open at time of test.

I wonder if this means that existing OLEObject code will start failing as people upgrade to the newer Outlook?

I notice that the Xojo docs don’t mention Outlook.Application anywhere. Did it previously?

Thanks. This is a fresh install just now of Outlook. I tried repair but it didn’t help.

I have a feeling that OLE is not supported in the new free version of Outlook. That version of Outlook seems to be more of an extension of Windows Mail.

I can’t seem to find anything definitive about this aside from a number of people stating it on stackoverflow, etc. Further to this, there is also a huge concern in other developer channels (MS Access for example) about Microsofts plans to drop COM/OLE support for Outlook in the future non-free version. It’s likley that this is already happening with this new free version (https://www.accessforever.org/post/the-new-outlook-and-access-vba).

From what I’m reading, I think you’ll have to switch to the full version of Outlook included in MS Office (ie. not the free version), or use Microsoft Graph API which is a whole other beast
(https://learn.microsoft.com/en-us/graph/use-the-ap)

The free Outlook is a Windows 11 app that is replacing the Mail App. It’s slowing rolling out to Windows 11 computers, and is still an optional update currently. I can’t for the life of me understand why Microsoft decided to name this new free app with the same name used for a long time enterprise level email client. Uff.

Ok. Done some testing:

“Old” Outlook. Works fine!
“New” Outlook. Fails.

This is the same regardless of whether you have a paid subscription or not.

In the old Outlook in the upper right is a slider to choose “New Outlook”. Doing so downloads a progressive web app. OLE can’t talk to it because it’s not a real app.

In fact, in your Microsoft 365 Apps chooser, clicking on Outlook opens Outlook in a browser.

As far as I can tell, this is Microsoft’s path forward. That means no more OLE as user’s upgrade.

As a bonus, the new Outlook lost an email I “sent” while offline and refuses to launch without an internet connection. Welcome to the future!

I have the same problem on macOS with AppleScript. Microsnot has announced AppleScript support like half a dozen times. And every time the feature was moved back. The latest time it was November 2023 and it’s now end of 2024.
image

The new Outlook(s) are horrible and a step backwards. I don’t know how Microsoft buggered this up so bad.

But AI will fix all this… muhaaa!

2 Likes

today if me open mail app it force to open outlook app at windows 10…
and new outlook app is with advertising or you have to pay 2$ a month …
thanks god we have Mozilla Thunderbird for free …

the best outlook was in office 1997 …

1 Like

It is using the name of the free app bundled in the os since windows 95…

Not having the 3 decades old COM technology for compatibility with windows 95 does not mean it is not a “real” app.

So as far as I can tell, the only route forward for talking to Outlook will be Microsoft Graph API. The outlook REST API is being killed off in March and OLE won’t be supported in the new Outlook.