Solved

Extracting messages from outlook

Posted on 2006-11-06
10
280 Views
Last Modified: 2008-01-09
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??

0
Comment
Question by:OFGemini
  • 5
  • 3
10 Comments
 
LVL 4

Expert Comment

by:MikeSel
ID: 17920838
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
0
 

Author Comment

by:OFGemini
ID: 18028924
What if I can't write anything to the userProperties??
0
 
LVL 4

Expert Comment

by:MikeSel
ID: 18029368
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!
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:OFGemini
ID: 18077455
MikeSel Have you gotten a chance to work any code out?
0
 
LVL 4

Expert Comment

by:MikeSel
ID: 18077507
Can you upload your code?
That way I can try and 'work it' in
0
 

Author Comment

by:OFGemini
ID: 18077911
   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
0
 
LVL 4

Accepted Solution

by:
MikeSel earned 500 total points
ID: 18078019
Will it not work on userProperties then?? as this way we will need to write the id's to a table in a db. An search them each time you do the export?
0
 
LVL 4

Expert Comment

by:MikeSel
ID: 18290980
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
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adding Namespace to the second node of the xml 16 78
Base1 Encode/Decode 3 82
iframe detection of parent window scale 20 85
youtube blocking politics 4 55
A short article about a problem I had getting the GPS LocationListener working.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question