Link to home
Start Free TrialLog in
Avatar of OFGemini
OFGemini

asked on

Extracting messages from outlook

I have an application that copies files from a user's outlook inbox the user's desktop.  It works great. however, If I run the application again it extracts the same messages again.  How can I tell if I have already extracted a certain message from the inbox already??

Avatar of MikeSel
MikeSel
Flag of United Kingdom of Great Britain and Northern Ireland image

When you have processed a mail item, why not set a userproperty something like this

Set myUserProperty = myItem.UserProperties _
    .Add("Saved2Desktop", True)


Then add something like

If Item.UserProperties.Find("Saved2Desktop") = True Then
    Exit Sub
End If
Avatar of OFGemini
OFGemini

ASKER

What if I can't write anything to the userProperties??
Then the only other way would be to store each item's unique id in some sort of file..


I am out on site atm so cant really work any code out..


I will try an do it when I get back!
MikeSel Have you gotten a chance to work any code out?
Can you upload your code?
That way I can try and 'work it' in
   Private Sub Export()


        Dim objOL As Outlook.Application
        Dim objNS As Outlook.NameSpace
        Dim olfolder As Outlook.MAPIFolder = Nothing
        Dim myItems As Outlook.Items
        Dim x As Int16
        Dim strFilePath As String = ""

        Try




            objOL = New Outlook.Application()
            objNS = objOL.GetNamespace("MAPI")
            olfolder = objOL.GetNamespace("MAPI").PickFolder


            If olfolder Is Nothing Then
                Exit Sub
            End If


            Dim fd As New FolderBrowserDialog

            If fd.ShowDialog = Windows.Forms.DialogResult.OK Then
                strFilePath = fd.SelectedPath
            Else
                Exit Sub
            End If

            myItems = olfolder.Items

            Dim sClassComp = "IPM.Note"


            For x = 1 To myItems.Count
                If myItems.Item(x).messageclass = sClassComp Then
                    Dim myMail As Outlook.MailItem = myItems(x)

                    Dim strFileName = Nothing

                    If myMail.Subject = "" Then
                        strFileName = "Untitled.msg"
                    Else
                        strFileName = myMail.Subject.Replace(":", "") & ".msg"
                    End If

                    myMail.SaveAs(System.IO.Path.Combine(strFilePath, strFileName), 3)
                End If

            Next x

        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            objOL = Nothing
            objNS = Nothing
            olfolder = Nothing
        End Try



    End Sub
ASKER CERTIFIED SOLUTION
Avatar of MikeSel
MikeSel
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You would need to save the item as well...

Set myUserProperty = myItem.UserProperties _
    .Add("Saved2Desktop", True)
myItem.save

Is this why you couldn't save to userproperties..


   Private Sub Export()

        Dim myUserProperty as UserProperty

        Dim objOL As Outlook.Application
        Dim objNS As Outlook.NameSpace
        Dim olfolder As Outlook.MAPIFolder = Nothing
        Dim myItems As Outlook.Items
        Dim x As Int16
        Dim strFilePath As String = ""

        Try




            objOL = New Outlook.Application()
            objNS = objOL.GetNamespace("MAPI")
            olfolder = objOL.GetNamespace("MAPI").PickFolder


            If olfolder Is Nothing Then
                Exit Sub
            End If


            Dim fd As New FolderBrowserDialog

            If fd.ShowDialog = Windows.Forms.DialogResult.OK Then
                strFilePath = fd.SelectedPath
            Else
                Exit Sub
            End If

            myItems = olfolder.Items

            Dim sClassComp = "IPM.Note"


            For x = 1 To myItems.Count
                If myItems.Item(x).messageclass = sClassComp Then
                    Dim myMail As Outlook.MailItem = myItems(x)

                    Dim strFileName = Nothing

                    If myMail.Subject = "" Then
                        strFileName = "Untitled.msg"
                    Else
                        strFileName = myMail.Subject.Replace(":", "") & ".msg"
                    End If

                    myMail.SaveAs(System.IO.Path.Combine(strFilePath, strFileName), 3)
                End If

Set myUserProperty = myMail.UserProperties _
    .Add("Saved2Desktop", True)
myMail.save


            Next x

        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            objOL = Nothing
            objNS = Nothing
            olfolder = Nothing
        End Try



    End Sub