Tjalve Posted October 15, 2012 Share Posted October 15, 2012 Hi everybody. Im trying to make a script that will dump every mail in the inbox folder into msgfiles. The mailbox in question is a mailbox that will recieve a copy of all the mails that come into our domain (so called journaling) and i what to dump them into msg files so that they will be easy to search through. Ive come as far as the code below. It works great, untill i get to a specific mail. Then i get an error message saying: The requested action with this object has failed.: $date = $m.ReceivedTime $date = $m.ReceivedTime^ ERROR Ok? It worked for the first 3000 mail, so whay not this mail? The mail in question is nothing strange, just anothe rmail like any other. So what im i doing wrong? I also tried to run the codw without getting the $date vriable. Just dump every mail with a uniqe name (in my case, a number based on the varible $c) and it works. So the question is, Why can i get $date = $m.ReceivedTime to work on most mail, but fails on another? Hers my code so far. expandcollapse popupGlobal $objOL = ObjCreate("Outlook.Application") Global $session = $objOL.GetNameSpace("MAPI") $inbox = $session.GetDefaultFolder(6) $c=0 if not FileExists(@DesktopDir &"\archived_email\") Then DirCreate(@DesktopDir & "\archived_email\") EndIf For $m In $inbox.items ;~ if $c > 200 then ExitLoop $c = $c + 1 $date = $m.ReceivedTime local $date_day[3] local $date_time[3] $date_day[0] = StringLeft($date,4) $date_day[1] = StringRight(StringLeft($date,6),2) $date_day[2] = StringRight(StringLeft($date,8),2) $date_time[0] = stringleft(stringright($date,6),2) $date_time[1] = stringleft(stringright($date,4),2) $date_time[2] = stringleft($date,2) $date_day2 = $date_day[1] & "-" & $date_day[2] $date_time2 = $date_time[0] & "-" & $date_time[1] & "-" & $date_time[2] ;~ ConsoleWrite($m.sendername & " --- " & $m.subject & " --- " & $m.ReceivedTime & @CRLF) ;~ $sendername = StringRegExpReplace($m.sendername,'[\/:*?"<>|]', '_') ;~ $receivedname = StringRegExpReplace($m.ReceivedByName,'[\/:*?"<>|]', '_') if not FileExists(@DesktopDir &"\archived_email\" & $date_day[0]) Then DirCreate(@DesktopDir & "\archived_email\" & $date_day[0]) EndIf if not FileExists(@DesktopDir &"\archived_email\" & $date_day[0] & "\" & $date_day2) Then DirCreate(@DesktopDir & "\archived_email\" & $date_day[0] & "\" & $date_day2) EndIf $fullname=@DesktopDir & "\archived_email\" & $date_day[0] & "\" & $date_day2 & "\" & $date_time2 & ".msg" if not FileExists($fullname) Then ConsoleWrite($c & " --- " & $fullname & @CRLF) $m.Saveas($fullname) EndIf Next $session.logoff Exit Link to comment Share on other sites More sharing options...
water Posted October 15, 2012 Share Posted October 15, 2012 Wouldn't it be easier search through the journal mailbox when someone needs to look for a mail? Why create another copy of all mails? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki  Link to comment Share on other sites More sharing options...
Tjalve Posted October 15, 2012 Author Share Posted October 15, 2012 (edited) I know that this is a kind of trashy way of doing it, but the mailbox in question is on a hosted exchgange server with limited storage and we have a local NAS that we what to store all the mailitems on. So for now the easiest solution (and cheapest) is ato have an Outlook klient just running and dumping all the mails from the online mailbox into a local store. The idee is to delete the mail from the inbox when the mail has been copied, Edited October 15, 2012 by Tjalve Link to comment Share on other sites More sharing options...
water Posted October 15, 2012 Share Posted October 15, 2012 In this case I would use a PST to receive the mails. Easier to search. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki  Link to comment Share on other sites More sharing options...
Tjalve Posted October 15, 2012 Author Share Posted October 15, 2012 Yes that is also an option. But in tha case i would need som kind of loop that "scans" the inbox for incomming mail and then dumps them into PST files. I tried using your UDF to list all the mail in the inbox, but i could not get it to work. Link to comment Share on other sites More sharing options...
water Posted October 15, 2012 Share Posted October 15, 2012 I would simply have a script that lists all mails in the inbox, copies all items to the PST and then deletes all successfully copied mails. Should be quite easy with my UDF._OL_Open() $aIn = _OL_FolderAccess(...Accessing the Inbox ...) $aOut = _OL_FolderAccess(... Accessing the PST ...) _OL_ItemFind(.. get all mailitems in the inbox ...) Loop _OL_ItemCopy(.. copy from $aIn to $aOut ...) If @error = 0 then _OL_ItemDelete(... item from $aIn ...) EndLoop _OL_Close My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki  Link to comment Share on other sites More sharing options...
Tjalve Posted October 15, 2012 Author Share Posted October 15, 2012 Yeah. Im trying to do just that as we speak. #include #include $oOutlook = _OL_Open() $Folder = _OL_FolderAccess($oOutlook, "", $olFolderInbox) $listofmail = _OL_ItemFind($oOutlook,$Folder,$olMail) _arraydisplay($listofmail) _OL_Close($oOutlook) Exit But i just get the error $oFolder = $oNamespace.Folders($aFolders[1]) $oFolder = $oNamespace.Folders($aFolders[1])^ ERROR Link to comment Share on other sites More sharing options...
water Posted October 15, 2012 Share Posted October 15, 2012 $listofmail = _OL_ItemFind($oOutlook, $Folder, $olMail)should be$listofmail = _OL_ItemFind($oOutlook, $Folder[1], $olMail) My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki  Link to comment Share on other sites More sharing options...
Tjalve Posted October 15, 2012 Author Share Posted October 15, 2012 Somtimes i feel so stupid... Thanks Water. Link to comment Share on other sites More sharing options...
water Posted October 15, 2012 Share Posted October 15, 2012 You don't have to! I once was staring for an hour or so on my script until I could solve the problem. Now I know where to look first My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki  Link to comment Share on other sites More sharing options...
Tjalve Posted October 15, 2012 Author Share Posted October 15, 2012 Gahh. I think om going mad... Sorry if this should be in the other forum, but since the issue is the same I will post here. I manged to get a list of all the items in my inbox. And now im trying to copy them to my PST (witch i Also managed to create). But it seems like the copyitem function doesnt take my folderobjekt thet i get from _OL_PSTGet. here is my code:#include #include $oOutlook = _OL_Open() ConsoleWrite("Access local inbox" & @CRLF) $Local_Folder = _OL_FolderAccess($oOutlook, "", $olFolderInbox) ConsoleWrite("Create New PST" & @CRLF) $PST1 = _OL_PSTCreate($oOutlook,@DesktopDir & "Mailarkiv4.pst","Mailarkiv4",$olStoreUnicode) ConsoleWrite("Access the PST" & @CRLF) $PST1_1 = _OL_PSTGet($oOutlook) ConsoleWrite("Polulate Array" & @CRLF) $listofmail = _OL_ItemFind($oOutlook, $Local_Folder[1], $olMail,"[UnRead]=True", "", "", "EntryID") ;~ _arraydisplay($listofmail) $i = 1 while 1 if $listofmail[0][0] = $i then ExitLoop ConsoleWrite("Copying mailItem: " & $i) _OL_ItemCopy($oOutlook,$listofmail[$i][0],"Default",$PST1_1[1][1]) ConsoleWrite(@error & @CRLF) $i = $i + 1 WEnd _OL_PSTClose($oOutlook,$PST1) _OL_Close($oOutlook) Exit I also tried using the varible $PST1 that i get when i create the PST, but it still doesnt work. I only get the anoying errror: The requested action with this object has failed.: $vItem = $oOL.Session.GetItemFromID($vItem, $sStoreID) $vItem = $oOL.Session.GetItemFromID($vItem, $sStoreID)^ ERROR Link to comment Share on other sites More sharing options...
water Posted October 15, 2012 Share Posted October 15, 2012 I stripped down your script a bit and put in some messages to the console so you can see if there is a problem and where.#include <OutlookEx.au3> $oOutlook = _OL_Open() ConsoleWrite("_OL_Open: " & @error & @LF) $Local_Folder = _OL_FolderAccess($oOutlook, "", $olFolderInbox) ConsoleWrite("_OL_FolderAccess: " & @error & @LF) $PST1 = _OL_PSTCreate($oOutlook, @DesktopDir & "Mailarkiv4.pst", "Mailarkiv4", $olStoreUnicode) ConsoleWrite("_OL_PSTCreate: " & @error & @LF) $listofmail = _OL_ItemFind($oOutlook, $Local_Folder[1], $olMail, "[UnRead]=True", "", "", "EntryID") ConsoleWrite("_OL_ItemFind: " & @error & @LF) ConsoleWrite("_OL_ItemFind: " & $listofmail[0][0] & " items found" & @LF) For $i = 1 To $listofmail[0][0] _OL_ItemCopy($oOutlook, $listofmail[$i][0], "Default", $PST1) ConsoleWrite("_OL_ItemCopy: " & @error & @LF) Next _OL_PSTClose($oOutlook, $PST1) ConsoleWrite("_OL_PSTClose: " & @error & @LF) _OL_Close($oOutlook) ConsoleWrite("_OL_Close: " & @error & @LF) Exit My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki  Link to comment Share on other sites More sharing options...
Tjalve Posted October 15, 2012 Author Share Posted October 15, 2012 Im adriad i get the same result and i still dont know whats wrong _OL_Open: 0 _OL_FolderAccess: 0 _OL_PSTCreate: 0 _OL_ItemFind: 0 _OL_ItemFind: 5 items found C:\Program Files (x86)\AutoIt3\Include\OutlookEx.au3 (2276) : ==> The requested action with this object has failed.: $vItem = $oOL.Session.GetItemFromID($vItem, $sStoreID) $vItem = $oOL.Session.GetItemFromID($vItem, $sStoreID)^ ERROR Link to comment Share on other sites More sharing options...
water Posted October 15, 2012 Share Posted October 15, 2012 Which version of the UDF do you use? Can be found in the first few lines of the UDF. Which version of AutoIt do you use? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki  Link to comment Share on other sites More sharing options...
Tjalve Posted October 15, 2012 Author Share Posted October 15, 2012 Autoit: 3.3.8.1 UDF Version ...: 0.8.0 Link to comment Share on other sites More sharing options...
water Posted October 15, 2012 Share Posted October 15, 2012 UDF version 0.8.0 is made for the 3.3.9.2 beta version of AutoIt. Can you download the latest 0.9.0.0 version? This version should work with all AutoIt versions. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki  Link to comment Share on other sites More sharing options...
Tjalve Posted October 15, 2012 Author Share Posted October 15, 2012 Alright. Now i got some more info. _OL_Open: 0 _OL_FolderAccess: 0 _OL_PSTCreate: 1 _OL_ItemFind: 0 _OL_ItemFind: 4 items found COM Error Encountered in mailexport4.au3 OutlookEx UDF version = 0.9.0 @AutoItVersion = 3.3.8.1 @AutoItX64 = 0 @Compiled = 0 @OSArch = X64 @OSVersion = WIN_8 Scriptline = 2320 NumberHex = 80020009 Number = -2147352567 WinDescription = Description = Det gick inte att öppna objektet. Försök igen. Source = Microsoft Outlook HelpFile = HelpContext = 0 LastDllError = 0 ======================================================== _OL_ItemCopy: 1 COM Error Encountered in mailexport4.au3 OutlookEx UDF version = 0.9.0 @AutoItVersion = 3.3.8.1 @AutoItX64 = 0 @Compiled = 0 @OSArch = X64 @OSVersion = WIN_8 Scriptline = 2320 NumberHex = 80020009 Number = -2147352567 WinDescription = Description = Det gick inte att öppna objektet. Försök igen. Source = Microsoft Outlook HelpFile = HelpContext = 0 LastDllError = 0 ======================================================== _OL_ItemCopy: 1 COM Error Encountered in mailexport4.au3 OutlookEx UDF version = 0.9.0 @AutoItVersion = 3.3.8.1 @AutoItX64 = 0 @Compiled = 0 @OSArch = X64 @OSVersion = WIN_8 Scriptline = 2320 NumberHex = 80020009 Number = -2147352567 WinDescription = Description = Det gick inte att öppna objektet. Försök igen. Source = Microsoft Outlook HelpFile = HelpContext = 0 LastDllError = 0 ======================================================== _OL_ItemCopy: 1 COM Error Encountered in mailexport4.au3 OutlookEx UDF version = 0.9.0 @AutoItVersion = 3.3.8.1 @AutoItX64 = 0 @Compiled = 0 @OSArch = X64 @OSVersion = WIN_8 Scriptline = 2320 NumberHex = 80020009 Number = -2147352567 WinDescription = Description = Det gick inte att öppna objektet. Försök igen. Source = Microsoft Outlook HelpFile = HelpContext = 0 LastDllError = 0 ======================================================== _OL_ItemCopy: 1 COM Error Encountered in mailexport4.au3 OutlookEx UDF version = 0.9.0 @AutoItVersion = 3.3.8.1 @AutoItX64 = 0 @Compiled = 0 @OSArch = X64 @OSVersion = WIN_8 Scriptline = 4363 NumberHex = 80020009 Number = -2147352567 WinDescription = Description = Matrisindex är utanför intervallet. Source = Microsoft Outlook HelpFile = HelpContext = 0 LastDllError = 0 ======================================================== _OL_PSTClose: 2 _OL_Close: 0 Link to comment Share on other sites More sharing options...
Tjalve Posted October 15, 2012 Author Share Posted October 15, 2012 (edited) I use the Swedish version of Office and this row: Description = Det gick inte att öppna objektet. Försök igen. Reads: Description = Could not open file objekt, try again Description = Matrisindex är utanför intervallet. reads: Description = Matrixindex is outside of the interval. Edited October 15, 2012 by Tjalve Link to comment Share on other sites More sharing options...
water Posted October 15, 2012 Share Posted October 15, 2012 This works for me now:#include <OutlookEx.au3> $oOutlook = _OL_Open() ConsoleWrite("_OL_Open: " & @error & @LF) $Local_Folder = _OL_FolderAccess($oOutlook, "", $olFolderInbox) ConsoleWrite("_OL_FolderAccess: " & @error & @LF) _OL_PSTCreate($oOutlook, "C:tempMailarchiv.pst", "Mailarchiv", $olStoreUnicode) ConsoleWrite("_OL_PSTCreate: " & @error & @LF) $oPST = _OL_PSTAccess($oOutlook, "C:tempMailarchiv.pst") ConsoleWrite("_OL_PSTAccess: " & @error & @LF) $listofmail = _OL_ItemFind($oOutlook, $Local_Folder[1], $olMail, "[UnRead]=True", "", "", "EntryID") ConsoleWrite("_OL_ItemFind: " & @error & @LF) ConsoleWrite("_OL_ItemFind: " & $listofmail[0][0] & " items found" & @LF) _arraydisplay($listofmail) For $i = 1 To $listofmail[0][0] _OL_ItemCopy($oOutlook, $listofmail[$i][0], Default, $oPST) ConsoleWrite("_OL_ItemCopy: " & @error & @LF) Next _OL_PSTClose($oOutlook, $oPST) ConsoleWrite("_OL_PSTClose: " & @error & @LF) _OL_Close($oOutlook) ConsoleWrite("_OL_Close: " & @error & @LF) Exit My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki  Link to comment Share on other sites More sharing options...
Tjalve Posted October 15, 2012 Author Share Posted October 15, 2012 yeah thats working for me to... But i cant see what you did diffrent from what I did? 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