' Assume success
Success = True
Error_Message = ""
NewID = ""
Try
' Verify that all input fields are present
Dim missingInput As String = Nothing
' Save the first empty input name
Select Case ""
Case Profile : missingInput = "Profile"
Case ID : missingInput = "ID"
End Select
' If any were empty, raise the error
If missingInput IsNot Nothing Then Throw New MAPIException( _
"{0} input parameter not set", missingInput)
' Initialise the extended MAPI interface
Using mapi As New NetMAPI()
'log into mapi
mapi.Login(Profile)
If Not mapi.OpenMessageStore() Then Throw New MAPIException( _
"Failed to access message store")
If Not mapi.OpenInbox() Then Throw New MAPIException( _
"Failed to access inbox")
If Move_to_Sub_Folder <> "" Then
Using msg As BPMAPIMessage = mapi.FindMessage(ID)
msg.MoveMessageTo(mapi, Move_to_Sub_Folder, Folder_Separator)
NewID = msg.ID
End Using
End If
End Using
Catch mex As MAPIException
Success = False
Error_Message = mex.GetActionMessage("Move Mail")
Catch e As Exception
Success = False
Error_Message = e.ToString()
End Try