'Outlook.MailItem' is not defined. Invoke code problem


#1

I want to use Invoke Code to read a local .msg file to get an attached file.

Dim OL As New Microsoft.Office.Interop.Outlook.Application
Dim Msg As Outlook.MailItem 
Msg = OL.CreateItemFromTemplate("C:\Users\az27355\Desktop\tempatt\original_email.eml.msg")
Console.WriteLine(Msg.Subject)

'TODO attached pdf = Msg.Attachment

First problem was to import Microsoft.Office.Interop.Outlook. I’ve seen others with similar issues and their solution only helped me partially.
The code failed at line 1 so I had to manually add to the xaml:
image

But the code still fails:

error BC30002: Type ‘Outlook.MailItem’ is not defined. At line 2


#2

@Tiramisu

Please look into Read a .msg file and save attachement

This might help you.


#3

I saw it but I’d rather not be depending on an external script. Thanks though.
It just makes deployment and maintenance more troublesome.