Results 1 to 12 of 12

Thread: VB6.0 - Office Outlook mail retrieval

Threaded View

  1. #1

    Thread Starter
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    VB6.0 - Office Outlook mail retrieval

    Hi,

    This is a Visual Basic 6.0 example I created back in 2005. This example shows you how to use the mapi components in VB to take advantage of Office Outlook (2003)'s email abilities. The MSMapi32.ocx is required in order for the code to work properly.

    Code:

    frmAttachments
    vb Code:
    1. 'Copyright 2005 "nightwalker83"
    2. Private Sub cmdAttach_Click()
    3. CDFiles.ShowOpen
    4. txtFile.Text = CDFiles.FileName
    5. LstFiles.AddItem CDFiles.FileName
    6. lblCount.Caption = lblCount.Caption + 1
    7. End Sub
    8.  
    9. Private Sub cmdCancel_Click()
    10. Unload Me
    11. End Sub
    12.  
    13. Private Sub cmdDelete_Click()
    14. For r = 0 To LstFiles.ListCount - 1
    15. LstFiles.RemoveItem (0)
    16. lblCount.Caption = lblCount.Caption - 1
    17. Next r
    18. txtFile.Text = ""
    19. End Sub
    20.  
    21. Private Sub cmdDone_Click()
    22. Me.Hide
    23. End Sub
    24.  
    25. Private Sub Form_Load()
    26. txtFile.Locked = True
    27. End Sub

    frmCompose
    vb Code:
    1. Private Sub cmdAttach_Click()
    2. 'Show attachments.
    3. frmAttachments.Show vbModal, Me
    4. End Sub
    5.  
    6. Private Sub cmdClear_Click()
    7. 'Clear all fields.
    8. txtTO.Text = ""
    9. txtSubject.Text = ""
    10. txtBody.Text = ""
    11. End Sub
    12.  
    13. Private Sub cmdClose_Click()
    14. 'Unload the form.
    15. Unload Me
    16. End Sub
    17.  
    18. Private Sub cmdSend_Click()
    19. 'Check whether or not to save then send the message.
    20.  frmMain.MAPIMessages1.MsgIndex = -1
    21. frmMain.MAPIMessages1.RecipAddress = txtTO.Text
    22. 'Double checks that address is valid.
    23. frmMain.MAPIMessages1.ResolveName
    24. frmMain.MAPIMessages1.MsgSubject = txtSubject.Text
    25. frmMain.MAPIMessages1.MsgNoteText = txtBody.Text
    26. 'Check for attachments.
    27. If frmAttachments.LstFiles.ListCount <> 0 Then
    28.  For a = 0 To frmAttachments.LstFiles.ListCount - 1
    29.  For S = 1 To (frmAttachments.LstFiles.ListCount)
    30.  sp = Split(frmAttachments.LstFiles.List(a), "\")
    31.  frmMain.MAPIMessages1.AttachmentName = sp(S)
    32.  Next S
    33.  frmMain.MAPIMessages1.AttachmentIndex = (a)
    34.   frmMain.MAPIMessages1.AttachmentPosition = (a)
    35. frmMain.MAPIMessages1.AttachmentPathName = frmAttachments.LstFiles.List(a)
    36. Next a
    37. End If
    38. 'Save the message.
    39. If chkSave.Value = 1 Then
    40. frmMain.MAPIMessages1.Save
    41. End If
    42. 'Send the message.
    43. frmMain.MAPIMessages1.Send (False)
    44. End Sub

    frmMain
    vb Code:
    1. Private Sub Form_Load()
    2. Dim itmM As ListItem, MCount As Variant, MsgCount As Variant, COLH As Integer
    3.  
    4. 'Logon to your Email account.
    5. MAPISession1.LogonUI = True
    6. 'Sign in to your email account.
    7. MAPISession1.SignOn
    8. 'Make sure the messages are used in the current session.
    9. MAPIMessages1.SessionID = MAPISession1.SessionID
    10. 'Download new mail from inbox.
    11. MAPISession1.DownLoadMail = False
    12. MAPIMessages1.FetchUnreadOnly = True
    13. MAPIMessages1.Fetch
    14. 'Sort the messages.
    15. MAPIMessages1.FetchSorted = True
    16. 'Check how many messages were received.
    17. MCount = MAPIMessages1.MsgCount
    18. 'Show received messages.
    19. For MsgCount = 0 To MCount - 1
    20. Next MsgCount
    21. 'Adjusts the index of each column so it can display the correct information.
    22. For COLH = 0 To 2
    23. Set itmM = LstNewMail.ListItems.Add(, , MAPIMessages1.MsgOrigAddress)
    24. COLH = COLH + 1
    25. itmM.SubItems(COLH) = MAPIMessages1.MsgSubject
    26. COLH = COLH + 1
    27. itmM.SubItems(COLH) = MAPIMessages1.MsgDateReceived
    28. Next COLH
    29. frmMain.Caption = frmMain.Caption & " " & "You have " & MsgCount & " new messages!"
    30. frmMain.Show
    31. End Sub
    32.  
    33. Private Sub Form_Unload(Cancel As Integer)
    34. 'Sign out of your email account.
    35. MAPISession1.SignOff
    36. End Sub
    37.  
    38. Private Sub mnuAddress_Click()
    39. 'Opens the address book.
    40. On Error Resume Next
    41. MAPIMessages1.Show
    42. End Sub
    43.  
    44. Private Sub mnuCompose_Click()
    45. 'Compose a new email message.
    46. frmCompose.Show vbModal, Me
    47. End Sub
    48.  
    49. Private Sub mnuExit_Click()
    50. 'Exit the application.
    51. Unload Me
    52. End
    53. End Sub
    54.  
    55. Private Sub mnuReadMessages_Click()
    56. 'Opens the form so you can read any new emails.
    57. frmRead.Show vbModal, Me
    58. End Sub

    frmRead
    vb Code:
    1. Private Sub cmdClose_Click()
    2. 'Unload the form.
    3. Unload Me
    4. End Sub
    5.  
    6. Private Sub cmdDelete_Click()
    7. 'Deletes current message.
    8. frmMain.MAPIMessages1.Delete
    9. txtBody.Text = ""
    10. txtSubject.Text = ""
    11. txtFrom.Text = ""
    12. frmMain.Refresh
    13. End Sub
    14.  
    15. Private Sub Form_Load()
    16. 'Locked the text disable the textboxes so they are read only.
    17. txtFrom.Enabled = False
    18. txtSubject.Enabled = False
    19. txtBody.Locked = True
    20. 'Get information from the message so it can be read.
    21. txtFrom.Text = frmMain.MAPIMessages1.MsgOrigAddress
    22. txtSubject.Text = frmMain.MAPIMessages1.MsgSubject
    23. txtBody.Text = frmMain.MAPIMessages1.MsgNoteText
    24. 'If there are no more messages disable the delete button.
    25.  If frmMain.MAPIMessages1.MsgCount = "0" Then
    26.   cmdDelete.Enabled = False
    27. End If
    28. End Sub

    Module1
    vb Code:
    1. Public a As Integer
    2. Public Path As String

    Nightwalker
    Attached Files Attached Files
    Last edited by Nightwalker83; Jun 19th, 2012 at 02:19 AM. Reason: Fixed spelling!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width