Results 1 to 12 of 12

Thread: Outlook Inegration

Hybrid View

  1. #1
    PowerPoster cicatrix's Avatar
    Join Date
    Dec 2009
    Location
    Moscow, Russia
    Posts
    3,654

    Re: Outlook Inegration

    Well, first you need to download and install
    Redistributable Primary Interop Assemblies for the MS Office version you are using.

    Then you should add a reference to the outlook interop assembly.

    Then try this code. It's been ported from VB6 so there might be some inconsitencies.
    vb.net Code:
    1. Public Sub ProcessInbox()
    2.     Dim oOutlook As Outlook.Application
    3.     Dim oNs As Outlook.NameSpace
    4.     Dim oFldr As Outlook.MAPIFolder
    5.     Dim oAttachments As Outlook.Attachments
    6.     Dim oAttachment As Outlook.Attachment
    7.     Dim iMsgCount As Integer
    8.  
    9.     Dim oMessage As Outlook.MailItem
    10.  
    11.     Dim iCtr As Long, iAttachCnt As Long
    12.  
    13.     Dim sFileNames As String
    14.     Dim aFileNames() As String
    15.  
    16.  
    17.      'get reference to inbox
    18.      oOutlook = New Outlook.Application
    19.      oNs = oOutlook.GetNamespace("MAPI")
    20.      oFldr = oNs.GetDefaultFolder(olFolderInbox)
    21.      Debug.WriteLine ("Total Items: " & oFldr.Items.Count)
    22.      Debug.WriteLine("Total Unread items = " & oFldr.UnReadItemCount)
    23.  
    24.  
    25.      For Each oMessage In oFldr.Items
    26.        
    27.          With oMessage
    28.          'basic info about message
    29.              Debug.WriteLine(.To)
    30.              Debug.WriteLine(.CC)
    31.              Debug.WriteLine(.Subject)
    32.              Debug.WriteLine(.Body)
    33.              If .UnRead Then
    34.                  Debug.WriteLine("Message has not been read")
    35.              Else
    36.                  Debug.WriteLine("Message has been read")
    37.              End If
    38.              iMsgCount = iMsgCount + 1
    39.              
    40.              'reference and save all attachments
    41.              With oMessage.Attachments
    42.                 iAttachCnt = .Count
    43.                 If iAttachCnt > 0 Then
    44.                     For iCtr = 1 To iAttachCnt
    45.                        .Item(iCtr).SaveAsFile "C:\" & .Item(iCtr).FileName
    46.                     Next iCtr
    47.                 End If
    48.             End With
    49.         End With
    50.         Application.DoEvents
    51.     Next oMessage
    52.    
    53. End Sub

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    321

    Re: Outlook Inegration

    Thank You my friend

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2008
    Posts
    321

    Re: Outlook Inegration

    Quote Originally Posted by cicatrix View Post
    Well, first you need to download and install
    Redistributable Primary Interop Assemblies for the MS Office version you are using.

    Then you should add a reference to the outlook interop assembly.

    Then try this code. It's been ported from VB6 so there might be some inconsitencies.
    vb.net Code:
    1. Public Sub ProcessInbox()
    2.     Dim oOutlook As Outlook.Application
    3.     Dim oNs As Outlook.NameSpace
    4.     Dim oFldr As Outlook.MAPIFolder
    5.     Dim oAttachments As Outlook.Attachments
    6.     Dim oAttachment As Outlook.Attachment
    7.     Dim iMsgCount As Integer
    8.  
    9.     Dim oMessage As Outlook.MailItem
    10.  
    11.     Dim iCtr As Long, iAttachCnt As Long
    12.  
    13.     Dim sFileNames As String
    14.     Dim aFileNames() As String
    15.  
    16.  
    17.      'get reference to inbox
    18.      oOutlook = New Outlook.Application
    19.      oNs = oOutlook.GetNamespace("MAPI")
    20.      oFldr = oNs.GetDefaultFolder(olFolderInbox)
    21.      Debug.WriteLine ("Total Items: " & oFldr.Items.Count)
    22.      Debug.WriteLine("Total Unread items = " & oFldr.UnReadItemCount)
    23.  
    24.  
    25.      For Each oMessage In oFldr.Items
    26.        
    27.          With oMessage
    28.          'basic info about message
    29.              Debug.WriteLine(.To)
    30.              Debug.WriteLine(.CC)
    31.              Debug.WriteLine(.Subject)
    32.              Debug.WriteLine(.Body)
    33.              If .UnRead Then
    34.                  Debug.WriteLine("Message has not been read")
    35.              Else
    36.                  Debug.WriteLine("Message has been read")
    37.              End If
    38.              iMsgCount = iMsgCount + 1
    39.              
    40.              'reference and save all attachments
    41.              With oMessage.Attachments
    42.                 iAttachCnt = .Count
    43.                 If iAttachCnt > 0 Then
    44.                     For iCtr = 1 To iAttachCnt
    45.                        .Item(iCtr).SaveAsFile "C:\" & .Item(iCtr).FileName
    46.                     Next iCtr
    47.                 End If
    48.             End With
    49.         End With
    50.         Application.DoEvents
    51.     Next oMessage
    52.    
    53. End Sub
    sorry one last thing -im trying to modify the code but it says "olFolderInbox" is not declared - what type shall i declare this as?

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