Figure 7   Retrieving Mail


 Sub RetrieveMail()
 
     On Error GoTo ErrorHandler
     Screen.MousePointer = vbHourglass
 
     Dim qry As New MSMQQuery
     Dim qInfo As MSMQQueueInfo
     Dim qInfos As MSMQQueueInfos
     Dim qReceive As MSMQQueue
     Dim msgObj As MSMQMessage
     Dim itm As ListItem
 
     ' clear out list view
     lvwMail.ListItems.Clear
 
     Set qInfos = qry.LookupQueue(, , Label:=sUserID)
     qInfos.Reset
 
     Set qInfo = qInfos.Next
 
     Set qReceive = qInfo.Open(Access:=MQ_RECEIVE_ACCESS, _
                               ShareMode:=MQ_DENY_NONE)
 
     Set msgObj = qReceive.PeekCurrent(True, True, 1000)
 
     Do While Not msgObj Is Nothing
         PopulateMailMessageInListView msgObj
         Set msgObj = qReceive.PeekNext(True, True, 1000)
     Loop
     Screen.MousePointer = vbNormal
 
     Exit Sub
 
 ErrorHandler:
     Screen.MousePointer = vbNormal
     MsgBox Err.Description, vbCritical
     Exit Sub
 
 End Sub


Figure 8   Sending Mail  


 Dim qry As New MSMQQuery
 Dim qInfo As MSMQQueueInfo
 Dim qInfos As MSMQQueueInfos
 Dim queSend As MSMQQueue
 Dim msgOut As New MSMQMessage
     
 Set qInfos = qry.LookupQueue(Label:=cbUsers)  ' find queue for user specified  
                                               ' in cbUsers combobox
 qInfos.Reset
 Set qInfo = qInfos.Next
 If qInfo Is Nothing Then
         MsgBox "No such queue.  Try again!"   ' No queue found
 Else
     Set queSend = qInfo.Open(MQ_SEND_ACCESS, 0)
     If queSend.IsOpen Then
         msgOut.Label = txtSubject
         msgOut.Priority = 4
         msgOut.body = txtMessage.Text
         msgOut.Send queSend
         Unload Me
     Else
         MsgBox "Unable to open connection to queue.  Please try again."
     End If
 End If