I am not able to compile your code, because header
doesn't contain RemoveAt
method. You have to call this method on mail.Headers
collection, not on a header itself.
You can do what you need like this:
' iterate through all headers
Dim i As Integer = 0
Do While i < (mail.Headers.Count - 1)
Dim header As Rebex.Mime.MimeHeader = mail.Headers(i)
If header.Name Like "Received" AndAlso InStr(header.Value.ToString, "prod.outlook.com") > 0 Then
' remove header (and keep index, because collection was shortened)
mail.Headers.RemoveAt(i)
Else
' update index to next header
i += 1
End If
Loop
Or, if you cannot do this in one loop, you can do the same in two step process like this:
' find headers to be removed
Dim headersToRemove = New List(Of Rebex.Mime.MimeHeader)
For Each header As Rebex.Mime.MimeHeader In mail.Headers
If header.Name Like "Received" AndAlso InStr(header.Value.ToString, "prod.outlook.com") > 0 Then
headersToRemove.Add(header)
End If
Next
' remove unwanted headers
For Each header In headersToRemove
mail.Headers.Remove(header)
Next