Jump to content

Outlook PST Question


klaki
 Share

Recommended Posts

I have a PST file loaded in my Outlook. What I want to do is to open the Inbox inside of my PST and go through each email. I want to take each email and copy certain parts of the body to an external file. Is this possible? If so, any help would be appreciated.

Thanks in advance,

Klaki

Link to comment
Share on other sites

I think you'd have to interact with Outlook to do this. Check out the MSDN Articles relating to VBA for Outlook 2003.

Then, of course, you need to convert the code for AutoIt, but that's child's play.

*EDIT* BTW, I would throw together some code, but we use *insert several explatives here* Lotus Notes at work and I don't have the energy to think about it at home.

Edited by c0deWorm

My UDFs: ExitCodes

Link to comment
Share on other sites

I think you'd have to interact with Outlook to do this. Check out the MSDN Articles relating to VBA for Outlook 2003.

Then, of course, you need to convert the code for AutoIt, but that's child's play.

*EDIT* BTW, I would throw together some code, but we use *insert several explatives here* Lotus Notes at work and I don't have the energy to think about it at home.

Thanks for the link. I will try to piece together something.

Link to comment
Share on other sites

if you can explain what exactly you want it to do, i can write you some VBA script to do it directly from outlook...

Open a folder (Logs) that is inside a personal folder.

Mailbox - Me (Exchange Mailbox)

|_Calander

|_Inbox

...

Personal Folder

|_Inbox

|_Logs

...

Then take the body in each email, manipulate it, and save certain lines to a new file.

Here is what I got. It works, but I have to use .PickFolder. I want a way to do this without using that. Here is the code:

MsgBox(0,"test","Creating Outlook Object")
$oOutlook = ObjCreate("Outlook.Application")
MsgBox(0,"test","Getting Namespace")
$oNameSpace = $oOutlook.GetNamespace("MAPI")
MsgBox(0,"test","Connecting to Personal Folder")
$oFld = $oNameSpace.PickFolder
$oEmails = $oFld.Items
$fLog = FileOpen("c:\test.txt",1)
For $iLoop = 1 to $oEmails.Count
;MsgBox(0,"test",$oEmails.Item($iLoop).Body)
    $aLog = StringSplit($oEmails.Item($iLoop).Body,Chr(13))
    For $iLoop2 = 2 to $aLog[0] 
        $aLog2 = StringSplit($aLog[$iLoop2],"-")
        For $iLoop3 = 2 to $aLog2[0]
        ;MsgBox(0,"test","Orginal Line: " & $aLog[$iLoop2])
            If (StringInStr($aLog2[3],"Log") = 0) Then
                $aLog3 = StringSplit($aLog2[4],",")
                $aLog4 = StringSplit($aLog2[5],",")
                If (($aLog3[2] = 80) Or ($aLog4[2] = 80)) Then
                ;MsgBox(0,"test",$aLog[$iLoop2])
                    FileWriteLine($fLog,$aLog[$iLoop2])
                EndIf
            EndIf
        Next
    ;MsgBox(0,"test",$aLog[$iLoop2])
    Next
Next
MsgBox(0,"test","Log completed..... closing")
FileClose($fLog)
$oEmails = ""
$oFld = ""
$oNameSpace = ""
$oOutlook = ""
Exit

Thanks in advance,

Klaki

Edited by klaki
Link to comment
Share on other sites

Open a folder (Logs) that is inside a personal folder.

Mailbox - Me (Exchange Mailbox)

|_Calander

|_Inbox

...

Personal Folder

|_Inbox

|_Logs

...

Then take the body in each email, manipulate it, and save certain lines to a new file.

Here is what I got. It works, but I have to use .PickFolder. I want a way to do this without using that. Here is the code:

MsgBox(0,"test","Creating Outlook Object")
$oOutlook = ObjCreate("Outlook.Application")
MsgBox(0,"test","Getting Namespace")
$oNameSpace = $oOutlook.GetNamespace("MAPI")
MsgBox(0,"test","Connecting to Personal Folder")
$oFld = $oNameSpace.PickFolder
$oEmails = $oFld.Items
$fLog = FileOpen("c:\test.txt",1)
For $iLoop = 1 to $oEmails.Count
;MsgBox(0,"test",$oEmails.Item($iLoop).Body)
    $aLog = StringSplit($oEmails.Item($iLoop).Body,Chr(13))
    For $iLoop2 = 2 to $aLog[0] 
        $aLog2 = StringSplit($aLog[$iLoop2],"-")
        For $iLoop3 = 2 to $aLog2[0]
;MsgBox(0,"test","Orginal Line: " & $aLog[$iLoop2])
            If (StringInStr($aLog2[3],"Log") = 0) Then
                $aLog3 = StringSplit($aLog2[4],",")
                $aLog4 = StringSplit($aLog2[5],",")
                If (($aLog3[2] = 80) Or ($aLog4[2] = 80)) Then
        ;MsgBox(0,"test",$aLog[$iLoop2])
                    FileWriteLine($fLog,$aLog[$iLoop2])
                EndIf
            EndIf
        Next
;MsgBox(0,"test",$aLog[$iLoop2])
    Next
Next
MsgBox(0,"test","Log completed..... closing")
FileClose($fLog)
$oEmails = ""
$oFld = ""
$oNameSpace = ""
$oOutlook = ""
Exit

Thanks in advance,

Klaki

instead of

$oFld = $oNameSpace.PickFolder

try:

$oFld = $oNameSpace.Folders("Folder Name")
Edited by cameronsdad
Link to comment
Share on other sites

Just out of curiousity, is this something you want to have run everyday, or is this a one-time thing? Judging from the code, it's a one-time thing, so the rest of this post is irrelevant. I say this because I don't see any code to check for whether the email is unread before touching it, nor does it delete the emails once it reads them.

If you are trying to do this on a regular basis or something, why not script the POP3 or IMAP connection instead of scripting Outlook? I think I saw some email UDF's in the forums at some point. Try searching if you're interested.

My UDFs: ExitCodes

Link to comment
Share on other sites

Just out of curiousity, is this something you want to have run everyday, or is this a one-time thing? Judging from the code, it's a one-time thing, so the rest of this post is irrelevant. I say this because I don't see any code to check for whether the email is unread before touching it, nor does it delete the emails once it reads them.

If you are trying to do this on a regular basis or something, why not script the POP3 or IMAP connection instead of scripting Outlook? I think I saw some email UDF's in the forums at some point. Try searching if you're interested.

It will be a monthly thing. I haven't tried doing it through IMAP. I will have to do some research on how to do so. I will be adding the "Move email" function later.

Link to comment
Share on other sites

did the replacement i suggested work for you?

No, I used the following:

$oFld = $oNameSpace.Folders("Test Personal Folders").Folder("Inbox")

And it gave me an error. The "Test Personal Folders" is the name of the personal folders and "Inbox" is where all the emails I want to sift through are located. Am I doing something wrong?

Thanks again

Link to comment
Share on other sites

No, I used the following:

$oFld = $oNameSpace.Folders("Test Personal Folders").Folder("Inbox")

And it gave me an error. The "Test Personal Folders" is the name of the personal folders and "Inbox" is where all the emails I want to sift through are located. Am I doing something wrong?

Thanks again

try:

$oPfFld = $oNameSpace.Folders("Test Personal Folders")
$oFld = $PfFld.Folders("Inbox")

the code you tried should have worked though... make sure that you're using the EXACT folder names.

Link to comment
Share on other sites

try:

$oPfFld = $oNameSpace.Folders("Test Personal Folders")
$oFld = $PfFld.Folders("Inbox")

the code you tried should have worked though... make sure that you're using the EXACT folder names.

Cam, it worked the original way. I put Folder when I should have put Folders, with the S. Thanks for getting that part fixed. Do you know by chance how to get the "Program is trying to access your folders" warning? I think if I do it using IMAP like codeworm suggested, it will work, but don't know how to do that.

Thanks bunches!

Link to comment
Share on other sites

Cam, it worked the original way. I put Folder when I should have put Folders, with the S. Thanks for getting that part fixed. Do you know by chance how to get the "Program is trying to access your folders" warning? I think if I do it using IMAP like codeworm suggested, it will work, but don't know how to do that.

Thanks bunches!

not sure i'm understanding... you WANT a notification that your folders are being accessed?
Link to comment
Share on other sites

not sure i'm understanding... you WANT a notification that your folders are being accessed?

When it accesses the folder, Outlook pops up a box and asks if you want to allow access to your email. You can set it for 1, 5, etc. minutes. Here is the box: Posted Image

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...