RedRocket86
New member
- Joined
- Jul 3, 2020
- Messages
- 4
- Programming Experience
- 1-3
Good afternoon,
I am struggling with the following piece of code.
When it reaches an email with a blank Subject or Body it throws an exception: "Object reference not set to an instance of an object"
I am really struggling with this, I have been googling all day and I'm at a bit of a dead end, any help would be really appreciated, it would help me a lot.
I've enabled Explicit and Strict and it it shows an error against the following lines:
Severity Code Description Project File Line Suppression State
Error BC30574 Option Strict On disallows late binding.
Severity Code Description Project File Line Suppression State
Error BC30512 Option Strict On disallows implicit conversions from 'Object' to 'MailItem'.
Full Code
I am struggling with the following piece of code.
When it reaches an email with a blank Subject or Body it throws an exception: "Object reference not set to an instance of an object"
I am really struggling with this, I have been googling all day and I'm at a bit of a dead end, any help would be really appreciated, it would help me a lot.
I've enabled Explicit and Strict and it it shows an error against the following lines:
VB.NET:
If otkMailItems.Item(iCntr).MessageClass = otkMailItem Then
otkMessage = otkMailItems.Item(iCntr)
Severity Code Description Project File Line Suppression State
Error BC30574 Option Strict On disallows late binding.
Severity Code Description Project File Line Suppression State
Error BC30512 Option Strict On disallows implicit conversions from 'Object' to 'MailItem'.
Full Code
VB.NET:
Try
Dim otkApp As Outlook.Application = New Outlook.Application
Dim otkMailItem = "IPM.Note"
Dim otkNameSpace As Outlook.NameSpace = otkApp.GetNamespace("MAPI")
Dim otkInboxFolder As Outlook.MAPIFolder = otkNameSpace.Folders("Test@Email.com").Folders("Inbox")
Dim otkMessage As Outlook.MailItem
Dim otkMailItems As Outlook.Items = otkInboxFolder.Items
Dim iCntr As Integer
otkMailItems = otkMailItems.Restrict("[Unread] = true")
For iCntr = 1 To otkMailItems.Count
If otkMailItems.Item(iCntr).MessageClass = otkMailItem Then
otkMessage = otkMailItems.Item(iCntr)
If otkMessage.Subject.Contains("Test1") And otkMessage.Body.Contains("Test2") And otkMessage.Body.Contains("Test3") Then
MsgBox("otkMessage.Subject.ToString")
End If
End If
Next
otkApp = Nothing
otkNameSpace = Nothing
otkMailItems = Nothing
otkMessage = Nothing
Catch ex As Exception
MsgBox(ex.Message)
End Try