klaki Posted February 28, 2006 Share Posted February 28, 2006 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 More sharing options...
Gigglestick Posted February 28, 2006 Share Posted February 28, 2006 (edited) 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 February 28, 2006 by c0deWorm My UDFs: ExitCodes Link to comment Share on other sites More sharing options...
klaki Posted March 1, 2006 Author Share Posted March 1, 2006 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 More sharing options...
seandisanti Posted March 1, 2006 Share Posted March 1, 2006 Thanks for the link. I will try to piece together something.if you can explain what exactly you want it to do, i can write you some VBA script to do it directly from outlook... Link to comment Share on other sites More sharing options...
klaki Posted March 2, 2006 Author Share Posted March 2, 2006 (edited) 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 March 2, 2006 by klaki Link to comment Share on other sites More sharing options...
seandisanti Posted March 3, 2006 Share Posted March 3, 2006 (edited) 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, Klakiinstead of $oFld = $oNameSpace.PickFolder try: $oFld = $oNameSpace.Folders("Folder Name") Edited March 3, 2006 by cameronsdad Link to comment Share on other sites More sharing options...
Gigglestick Posted March 3, 2006 Share Posted March 3, 2006 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 More sharing options...
klaki Posted March 6, 2006 Author Share Posted March 6, 2006 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 More sharing options...
seandisanti Posted March 6, 2006 Share Posted March 6, 2006 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.did the replacement i suggested work for you? Link to comment Share on other sites More sharing options...
klaki Posted March 6, 2006 Author Share Posted March 6, 2006 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 More sharing options...
seandisanti Posted March 6, 2006 Share Posted March 6, 2006 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 againtry: $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 More sharing options...
klaki Posted March 6, 2006 Author Share Posted March 6, 2006 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 More sharing options...
seandisanti Posted March 6, 2006 Share Posted March 6, 2006 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 More sharing options...
klaki Posted March 6, 2006 Author Share Posted March 6, 2006 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: Link to comment Share on other sites More sharing options...
seandisanti Posted March 6, 2006 Share Posted March 6, 2006 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: and you WANT that to pop up? or no? Link to comment Share on other sites More sharing options...
klaki Posted March 6, 2006 Author Share Posted March 6, 2006 and you WANT that to pop up? or no?NO popup, just extra clicks. Link to comment Share on other sites More sharing options...
Gigglestick Posted March 6, 2006 Share Posted March 6, 2006 Use ControlSend and ControlClick... or I think you can disable that altogether in the security options somewhere. My UDFs: ExitCodes Link to comment Share on other sites More sharing options...
Gigglestick Posted March 6, 2006 Share Posted March 6, 2006 (edited) If you are seriously considering scripting POP3 for this, you might look at this thread or this thread. Edited March 6, 2006 by c0deWorm My UDFs: ExitCodes Link to comment Share on other sites More sharing options...
klaki Posted March 7, 2006 Author Share Posted March 7, 2006 If you are seriously considering scripting POP3 for this, you might look at this thread or this thread.I don't believe POP3 is turned on at the server, so IMAP would be my only option, but thanks for the links, I will definately look them over. Link to comment Share on other sites More sharing options...
Gigglestick Posted March 7, 2006 Share Posted March 7, 2006 So is this an Exchange server your Outlook is connected to then? How is the email getting into the PST? If POP3 is disabled on the server, then most likely so is IMAP. I guess you'll have to do it this way. My UDFs: ExitCodes Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now