Private Sub Form_Load() MAPISession1.SignOn End Sub
9、将下列代码加入Form1的Form_Unload事件:
Private Sub Form_Unload(Cancel As Integer) MAPISession1.SignOff End Sub
10、将下列代码加入cmdSend的Click事件:
Private Sub cmdSend_Click() With MAPIMessages1 .MsgIndex = -1 .RecipDisplayName = txtSendTo.Text .MsgSubject = txtSubject.Text .MsgNoteText = txtMessage.Text .SessionID = MAPISession1.SessionID .Send End With MsgBox "邮件发送完毕!", , "发送邮件" End Sub
Public Sub FetchNewMail() MAPIMessages1.FetchUnreadOnly = True MAPIMessages1.Fetch End Sub
11、编写一个窗体级子例程DisplayMessage:
Public Sub DisplayMessage() lblMsgCount.Caption = "第 " & _ LTrim(Str(MAPIMessages1.MsgIndex + 1)) & " 封邮件,总计 " & _ LTrim(Str(MAPIMessages1.MsgCount)) & " 封邮件" lblMsgDateReceived.Caption = MAPIMessages1.MsgDateReceived txtMsgNoteText.Text = MAPIMessages1.MsgNoteText lblMsgOrigDisplayName.Caption = MAPIMessages1.MsgOrigDisplayName lblMsgSubject.Caption = MAPIMessages1.MsgSubject End Sub
12、将下列代码加入Form1的Form_Load事件:
Private Sub Form_Load() MAPISession1.SignOn MAPIMessages1.SessionID = MAPISession1.SessionID FetchNewMail DisplayMessage End Sub
13、将下列代码加入cmdPrevious的Click事件:
Private Sub cmdPrevious_Click() If MAPIMessages1.MsgIndex > 0 Then MAPIMessages1.MsgIndex = MAPIMessages1.MsgIndex - 1 DisplayMessage Else Beep End If End Sub
14、将下列代码加入cmdNext的Click事件:
Private Sub cmdNext_Click() If MAPIMessages1.MsgIndex < MAPIMessages1.MsgCount - 1 Then MAPIMessages1.MsgIndex = MAPIMessages1.MsgIndex + 1 DisplayMessage Else Beep End If End Sub