Jump to content
Smigacznr1

Outlook cleaner OutlookEX

Recommended Posts

Smigacznr1

I'm writing Outlook pst cleaner and now I'm stuck. Compiled script is crashing with OS crash message. When I tryied to run script from editor it's exiting itself (mabye it's some type of crash?) always when it's processing on 4-rd pst file. Here is my code:

#include <OutlookEX.au3>
#include <Date.au3>
#include <File.au3>
#include <Array.au3>

_cleanOutlook("Administrator")
_cleanOutlook("Admin")


Exit

Func _cleanOutlook($user)

    $foldery = "Wiadomości-śmieci#?SPAM#?Junk E-mail#?Elementy usunięte#?Deleted Items"
    $tab_folderow = StringSplit($foldery, "#?", 1)

    $tab_pst = _FileListToArrayRec("c:\users\" & $user, "*.pst", 1+4+8, 1, 0, 2)
;~  _ArrayDisplay($tab_pst)

    For $d = 1 To UBound($tab_pst) -1 Step +1

        $outlook = _OL_Open(True)
        _OL_Close($outlook, True)

        $outlook = _OL_Open()

        Local $aStores = _OL_StoreGet($outlook)
    ;~      _ArrayDisplay($aStores)
        For $i = 1 to $aStores[0][0]
            If $aStores[$i][4] = True Then
    ;~          ConsoleWrite(@CRLF & "zamykam pst 2")
                _OL_PSTClose($outlook,$aStores[$i][0])
            EndIf
        Next

;~      _OL_PSTAccess($outlook, "C:\Users\Administrator\Desktop\cos.pst")
        _OL_PSTAccess($outlook, $tab_pst[$d])

        ConsoleWrite(@CRLF & $tab_pst[$d])
;~      $tab_struktury = _OL_FolderTree($outlook, "*", 10)
;~      If @error Then
;~          ContinueLoop
;~      EndIf
;~      _ArrayDisplay($tab_struktury)

        $tab_ktory_pst = _OL_PSTGet($outlook)
;~          _ArrayDisplay($tab_ktory_pst)
        For $a = 0 To UBound($tab_ktory_pst) -1 Step +1

            If $tab_ktory_pst[$a][2] = $tab_pst[$d] Then
;~                  MsgBox(0, "", $tab_ktory_pst[$a][0])
                $nazwa_bazy_pst = $tab_ktory_pst[$a][0]
            EndIf

        Next

;~      MsgBox(0, "", UBound($tab_folderow))
;~      _ArrayDisplay($tab_folderow, $tab_pst[$d])

        ConsoleWrite(@CRLF & "przed while")

        $a = 0

        While $a < 2

            ConsoleWrite(@CRLF & "while 1")

            For $b = 1 To UBound($tab_folderow) -1 Step +1

                ConsoleWrite(@CRLF & "for 1")

                $tab_struktury = _OL_FolderTree($outlook, $nazwa_bazy_pst)
;~              _ArrayDisplay($tab_struktury, $nazwa_bazy_pst)

;~              $folder = _OL_FolderAccess($outlook, StringTrimLeft($tab_struktury[0], 2) & "\" & $tab_folderow[$b])
                $folder = _OL_FolderAccess($outlook, $nazwa_bazy_pst & "\" & $tab_folderow[$b])
;~              ConsoleWrite(@CRLF & "eeee")
                If @error Then
;~                  MsgBox(0, "", "\\" & $nazwa_bazy_pst & "\" & $tab_folderow[$b] & @CRLF & @error)
                    ConsoleWrite(@CRLF & "przechodze do kolejnego " & $b+1)
                    ContinueLoop
                EndIf
;~              _ArrayDisplay($folder, $nazwa_bazy_pst)

                ConsoleWrite(@CRLF & $tab_folderow[$b])

                If $tab_folderow[$b] = "Deleted Items" Or $tab_folderow[$b] = "Elementy usunięte" Then

                    ConsoleWrite(@CRLF & "usuwam kosze")
                    _OL_FolderDelete($outlook, $folder[1], 1)
                    _OL_FolderDelete($outlook, $folder[1], 2)
                    _OL_FolderDelete($outlook, $folder[1], 3)
                    _OL_FolderDelete($outlook, $folder[1], 4)
;~                  _OL_FolderDelete($outlook, $folder[1], 5)

                EndIf

                If $a = 0 Then

                    $tab_maile = ""

                    $data_dzis = @YEAR & "/" & @MON & "/" & @MDAY & " 00:00"
        ;~          $data_dzis = "2017/01/31 00:00"
                    $data_szukana = _DateAdd("D", "-3", $data_dzis)

                    $tab_maile = _OL_ItemFind($outlook, $folder[1], $olMail, "[Received]<'" & StringReplace($data_szukana, "/", "-") & "'", "", "", "EntryID", "", 1)
                    If @error Then
                        ContinueLoop
                    EndIf
        ;~          If UBound($tab_maile) > 1 Then
        ;~              _ArrayDisplay($tab_maile)
        ;~          EndIf

                    If UBound($tab_maile) > 1 Then

                        For $c = 1 To UBound($tab_maile) -1 Step +1

;~                          ConsoleWrite(@CRLF & "usuwam stare maile")
                            _OL_ItemDelete($outlook, $tab_maile[$c][0], "", False)

                        Next

                    EndIf

                EndIf

            Next


            $a = $a + 1

        WEnd


;~      ConsoleWrite(@CRLF & "pokazuje")
;~      $folder[1].Display
        $olFolderInbox.Display

;~      _OL_PSTClose($outlook, $olFolderInbox)
;~      If @error Then
;~          MsgBox(0, "", @error)
;~      EndIf

        Local $aStores = _OL_StoreGet($outlook)
;~      _ArrayDisplay($aStores)
        For $i = 1 to $aStores[0][0]
            If $aStores[$i][4] = True Then
;~              ConsoleWrite(@CRLF & "zamykam pst 1")
                _OL_PSTClose($outlook,$aStores[$i][0])
            EndIf
        Next

        ;_OL_PSTClose($outlook, $folder[1])

        _OL_Close($outlook, True)
        If @error Then
            MsgBox(0, "", @error)
        EndIf

        ConsoleWrite(@CRLF & "zamykam")

        ProcessWaitClose("outlook.exe", 30)

        ProcessClose("outlook.exe")

    Next

EndFunc

 

Outlook and OS is updated. I'm usinn OutlooEX in ver. 1.3.1.0

Any ideas? :)

 

Share this post


Link to post
Share on other sites
water

Just a few questions:

  • Why do you Open, Close and then Reopen Outlook in the loop?
  • Why do you call _OL_FolderDelete multiple times? Simply use $iFlags = 0 to delete the folder, all items and all subfolders.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Smigacznr1

I'm reopening outlook inside loop because it was my last idea to check yesterday. I thought that mabye outlook have some limitation, but  nothing changed.

I don't want to delete whole folder but everything what is inside.

Share this post


Link to post
Share on other sites
water

Only call _OL_Open once and move it outside the main loop and close Outlook before you exit the function.
To only delete the items set $iFlag = 2 (does not delete any folders or subfolders - just items)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Smigacznr1

Moving out _OL_Open it's not solution for my problem. It doesn't matter if it will be inside or outside loop.

To delete items in folder, all subfolders but leave folder itself I need to use flag 5, right (4+1)?

Share this post


Link to post
Share on other sites
water

Moving _OL_Open enhances performance.
Correct.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Smigacznr1

Ok, what about crash problem?

Share this post


Link to post
Share on other sites
water

Please post the messages you get when running the script from SciTE.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Smigacznr1

Sure. Here you are:

Quote

>"C:\Program Files\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\Administrator\Desktop\outlook.au3" /UserParams    
+>12:18:45 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0   Keyboard:00000415  OS:WIN_7/Service Pack 1  CPU:X86 OS:X86  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files\AutoIt3\SciTE   UserDir => C:\Users\Administrator\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Administrator\AppData\Local\AutoIt v3\SciTE
>Running AU3Check (3.3.14.2)  from:C:\Program Files\AutoIt3  input:C:\Users\Administrator\Desktop\outlook.au3
+>12:18:46 AU3Check ended.rc:0
>Running:(3.3.14.2):C:\Program Files\AutoIt3\autoit3.exe "C:\Users\Administrator\Desktop\outlook.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop

c:\users\Administrator\Documents\Pliki programu Outlook\Outlook.pst
przed while
while 1
for 1
Wiadomoœci-œmieci
for 1
przechodze do kolejnego 3
for 1
przechodze do kolejnego 4
for 1
Elementy usuniête
usuwam kosze
for 1
przechodze do kolejnego 6
while 1
for 1
Wiadomoœci-œmieci
for 1
przechodze do kolejnego 3
for 1
przechodze do kolejnego 4
for 1
Elementy usuniête
usuwam kosze
for 1
przechodze do kolejnego 6
c:\users\Administrator\Documents\Pliki programu Outlook\test@cos.cl.pst
przed while
while 1
for 1
przechodze do kolejnego 2
for 1
przechodze do kolejnego 3
for 1
Junk E-mail
for 1
Elementy usuniête
usuwam kosze
for 1
przechodze do kolejnego 6
while 1
for 1
przechodze do kolejnego 2
for 1
przechodze do kolejnego 3
for 1
Junk E-mail
for 1
Elementy usuniête
usuwam kosze
for 1
przechodze do kolejnego 6
c:\users\Administrator\Documents\Pliki programu Outlook\test@firmaadams.ex.pst
przed while
while 1
for 1
Wiadomoœci-œmieci
for 1
przechodze do kolejnego 3
for 1
przechodze do kolejnego 4
for 1
przechodze do kolejnego 5
for 1
przechodze do kolejnego 6
while 1
for 1
przechodze do kolejnego 2
for 1
przechodze do kolejnego 3
for 1
przechodze do kolejnego 4
for 1
przechodze do kolejnego 5
for 1
przechodze do kolejnego 6
c:\users\Administrator\Documents\Outlook Files\Outlook.pst
przed while
while 1
for 1!>12:18:55 AutoIt3.exe ended.rc:-1073741819
+>12:18:55 AutoIt3Wrapper Finished.
>Exit code: 3221225477    Time: 11.3

 

 

Share this post


Link to post
Share on other sites
water

When you search the forum for "1073741819" (mind the removed -) then you will get a lot of hits. Seems to be a problem with how your script is coded.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Smigacznr1

It's crashing on

$folder = _OL_FolderAccess($outlook, $nazwa_bazy_pst & "\" & $tab_folderow[$b])

So it's OutlooEX.au3 function problem?

Share this post


Link to post
Share on other sites
water

Most of the time it is a problem with the parameters you provide. Can you make sure that all three variables contain valid data?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Smigacznr1

When I added

If $tab_ktory_pst = "" Then
                    ConsoleWrite(@CRLF & $nazwa_bazy_pst & "\" & $tab_folderow[$b])
                EndIf

before

$folder = _OL_FolderAccess($outlook, $nazwa_bazy_pst & "\" & $tab_folderow[$b])

it's running fine. How to explain it?

 

Update:

After few compilations it's not running properly again. Strange is that I did not any changes in code...

Variables what I passed to  _OL_FolderAccess are: dh14@firmaadams.pl\SPAM

Variables are correct.

 

Update 15:20:

Ok, I get it! This part of code causes crash :

_OL_FolderDelete($outlook, $folder[1], 1)
                    _OL_FolderDelete($outlook, $folder[1], 2)
                    _OL_FolderDelete($outlook, $folder[1], 3)
                    _OL_FolderDelete($outlook, $folder[1], 4)
                    _OL_FolderDelete($outlook, $folder[1], 5)

Calling _OL_FolderDelete multiple times in this same loop, on this same folder causing crash.

Problem solved :)

Edited by Smigacznr1
update

Share this post


Link to post
Share on other sites
water

Can you please explain in words what you try to achieve with your script?
As far as I understand you want to

  • Process all PST files in a folder
  • empty the "deleted items" folder (or how it is named in your language)
  • for all other folders you want to delete all items older x days.

Question:

  • Why do you do this two times (While $a < 2)?
  • Why do you close all PST stores in a loop? Couldn't you just close all of them when starting the script and then process each PST file in a loop?

Suggestions:

  • Access the default folders ("deleted items", "Junk" ...) not by name but by foldertype. So your script becomes language independant.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Smigacznr1
On 24.03.2017 at 3:33 PM, water said:

Can you please explain in words what you try to achieve with your script?
As far as I understand you want to

  • Process all PST files in a folder
  • empty the "deleted items" folder (or how it is named in your language)

That's right.

On 24.03.2017 at 3:33 PM, water said:

Question:

  • Why do you do this two times (While $a < 2)?

I thought that elements deleted from any folder are moved to trash folder, not deleted permanently. But now i removed it and added purge default trash folder at the end of loop.

On 24.03.2017 at 3:33 PM, water said:
  • Why do you close all PST stores in a loop? Couldn't you just close all of them when starting the script and then process each PST file in a loop?

I don't want to leave outlook on Administrator profile with all user files connected to it ;)

Idea is to clean outlook files in whole organization because users don't care about their profiles...

On 24.03.2017 at 3:33 PM, water said:

Suggestions:

  • Access the default folders ("deleted items", "Junk" ...) not by name but by foldertype. So your script becomes language independant.

Good idea, I added it to the end of loop. But we have in our organization outlook files with folders in another languages ex. folder trash in english and polish, so I need to select excatly folder anyway....

Your suggestions are helpful, thanks.

 

Script is crashing again now. For now i have no idea what is wrong. Mabye could you take a look again?

 

Share this post


Link to post
Share on other sites
water

Will check as soon as I find some spare time - might take a few days.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Smigacznr1

Here you are updated script:

#include <OutlookEX.au3>
#include <Date.au3>
#include <File.au3>
#include <Array.au3>

_cleanOutlook("Administrator")

_cleanOutlook("Admin")

Exit

Func _cleanOutlook($user)

    $foldery = "Wiadomości-śmieci#?SPAM#?Junk E-mail#?Elementy usunięte#?Deleted Items"
    $tab_folderow = StringSplit($foldery, "#?", 1)
    
    $tab_pst = _FileListToArrayRec("c:\users\" & $user, "*.pst", 1 + 4 + 8, 1, 0, 2)

    $outlook = _OL_Open()
    
    Local $aStores = _OL_StoreGet($outlook)
    For $i = 1 To $aStores[0][0]
        _OL_PSTClose($outlook, $aStores[$i][0])
    Next
    
    For $d = 1 To UBound($tab_pst) - 1 Step +1

        _OL_PSTAccess($outlook, $tab_pst[$d])
        If @error Then
            ContinueLoop
        EndIf
        ConsoleWrite(@CRLF & $tab_pst[$d])
        $tab_ktory_pst = _OL_PSTGet($outlook)
        If @error Then
            ContinueLoop
        EndIf

        For $a = 0 To UBound($tab_ktory_pst) - 1 Step +1
            If $tab_ktory_pst[$a][2] = $tab_pst[$d] Then
                $nazwa_bazy_pst = $tab_ktory_pst[$a][0]
            EndIf
        Next

        ConsoleWrite(@CRLF & "przed for 1")
        
        For $b = 1 To UBound($tab_folderow) - 1 Step +1
        
            ConsoleWrite(@CRLF & "for 1")

            If $tab_pst[$d] = "c:\users\Administrator\Desktop\japierdo.pst" Then
                ConsoleWrite(@CRLF & $nazwa_bazy_pst & "\" & $tab_folderow[$b])
                MsgBox(0, "", $nazwa_bazy_pst & "\" & $tab_folderow[$b])
            EndIf
            
            $folder = _OL_FolderAccess($outlook, $nazwa_bazy_pst & "\" & $tab_folderow[$b])
            If @error Then
                ConsoleWrite(@CRLF & "przechodze do kolejnego " & $b + 1)
                ContinueLoop
            EndIf

            ConsoleWrite(@CRLF & $tab_folderow[$b])
            
            If $tab_folderow[$b] = "Deleted Items" Or $tab_folderow[$b] = "Elementy usunięte" Then
                ConsoleWrite(@CRLF & "usuwam kosze")
                _OL_FolderDelete($outlook, $folder[1], 5)
                ContinueLoop
            EndIf
            
            $tab_maile = ""
            $data_dzis = @YEAR & "/" & @MON & "/" & @MDAY & " 00:00"
            $data_szukana = _DateAdd("D", "-3", $data_dzis)
            $tab_maile = _OL_ItemFind($outlook, $folder[1], $olMail, "[Received]<'" & StringReplace($data_szukana, "/", "-") & "'", "", "", "EntryID", "", 1)
            If @error Then
                ContinueLoop
            EndIf

            If UBound($tab_maile) > 1 Then
                For $c = 1 To UBound($tab_maile) - 1 Step +1
                    _OL_ItemDelete($outlook, $tab_maile[$c][0], "", False)
                Next
            EndIf
            
            $folder = _OL_FolderAccess($outlook, $nazwa_bazy_pst & "\" & $olFolderJunk)
            If Not @error Then
                $tab_maile = ""
                $tab_maile = _OL_ItemFind($outlook, $folder[1], $olMail, "[Received]<'" & StringReplace($data_szukana, "/", "-") & "'", "", "", "EntryID", "", 1)
                If @error Then
                    ContinueLoop
                EndIf

                If UBound($tab_maile) > 1 Then
                    For $c = 1 To UBound($tab_maile) - 1 Step +1
                        _OL_ItemDelete($outlook, $tab_maile[$c][0], "", False)
                    Next
                EndIf
            EndIf
        Next
        
        $folder = _OL_FolderAccess($outlook, $nazwa_bazy_pst & "\" & $olFolderDeletedItems)
        If Not @error Then
            ConsoleWrite(@CRLF & "Usuwam kosz koniec")
            _OL_FolderDelete($outlook, $folder[1], 5)
        EndIf
        
        $olFolderInbox.Display
        Local $aStores = _OL_StoreGet($outlook)
        For $i = 1 To $aStores[0][0]
            _OL_PSTClose($outlook, $aStores[$i][0])
        Next
        
    Next
    
    _OL_Close($outlook, True)
    If @error Then
        MsgBox(0, "", @error)
    EndIf
    
    ConsoleWrite(@CRLF & "zamykam")
    
    ProcessWaitClose("outlook.exe", 30)
    
    ProcessClose("outlook.exe")

    Return
    
EndFunc

 

Edited by Smigacznr1

Share this post


Link to post
Share on other sites
water

First code example: Clear specified folders of an PST by removing all items and all subfolders.

#include-once
#include "..\OutlookEX.au3"
#include <Date.au3>
#include <File.au3>
#include <Array.au3>

Global $oOL = _OL_Open()
$oPSTRoot = _OL_PSTAccess($oOL, "C:\temp\Outlook-UDF-Test.pst")
_ClearFolder($oPSTRoot, $olFolderDeletedItems)
If @error Then Exit MsgBox($MB_ICONERROR, "Error", "Could not clean folder 'Deleted items'. @error = " & @error & ", @extended = " & @extended)
_ClearFolder($oPSTRoot, $olFolderDrafts)
If @error Then Exit MsgBox($MB_ICONERROR, "Error", "Could not clean folder 'Drafts'. @error = " & @error & ", @extended = " & @extended)
_ClearFolder($oPSTRoot, $olFolderJunk)
If @error Then Exit MsgBox($MB_ICONERROR, "Error", "Could not clean folder 'Junk'. @error = " & @error & ", @extended = " & @extended)

Func _ClearFolder($oRootFolder, $iFolderType)
    Local $oStore = $oRootFolder.Store()
    Local $oFolder = $oStore.GetDefaultFolder($iFolderType)
    _OL_FolderDelete($oOL, $oFolder, 5)
    If @error Then Return SetError(@error, @extended)
EndFunc

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
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

  • Similar Content

    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Friends,
      I am having a requirement where i have to automate outllook.I have to send mail using outlook.Whe i went through the forum i got OutLookEx.au3 but when i am trying to use this i am getting error can anyone help me in using this? @water
    • Gowrisankar
      By Gowrisankar
      Dear members of the forum,
      I'm working on a project where incoming emails are to be analyzed based on the subject line and moved to various folders in a shared mailbox.
      I'm using "OutlookEx.au3" of @water. The macro can can move emails  to any folder that I newly create. But the macro couldn't move emails to specific folders that are already existing.
      I checked the permission levels of those folders and found that nothing is wrong with that. The function I use is _OL_ItemMove.
      Please guide me how to proceed further. Thanks in advance.
      -Gowrisankar.
       
    • nooneclose
      By nooneclose
      Good morning everyone, I thought I had already solved this issue but it turns out I did not. 
      My code finds unread emails with this specific subject line of "request" but when I change the subject to SKIPPED + "request" = ("SKIPPED request") the program still finds the email and tries to process it. I only want to process emails with the exact match subject of "request".
      Here is my code that "finds" the unread emails with the subject of "request" or so I thought. 
      Func ListUnreadEmails() ;******************************************************************************* ; Lists all unread E-mails from the folder Outlook-UDF-Test ;******************************************************************************* ; Stores all the unRead emails into an array Global $aItems = _OL_ItemFind($oOutlook, "*\Outlook-UDF-Test", $olMail, _ "[UnRead]=True", "Subject", "request", "EntryID,Subject", "", 1) ; Displays the array of unRead emails If IsArray($aItems) Then ;_ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind - Unread mails") Else MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", _ "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended) EndIf ; Gets the number of unread emails Global $numberOfUnRead = UBound($aItems, $UBOUND_ROWS) - 1 ;MsgBox("", "Number of Unread emails", $numberOfUnRead) EndFunc It acts as if any part of the subject containing the word "request" and the email is unread that it will try to process it. (I think)
    • nooneclose
      By nooneclose
      Good afternoon, I am in need of some help. I am sure this is a stupid question requiring only one or two lines of code. However, I would greatly appreciate the help I cannot figure this out. I also tried searching for the answer on the internet but no one except me apparently seems to be having a hard time figuring this out and or is asking about it. 
      I simply want to change the "status" of an email from unread to read once I have processed it. My code is over 500 lines and I would like not to clutter this post with it. Assume I have all my includes and connections properly defined and stuff. 
      Here is the bit of code where I am trying to change the email that was used from unread to read:
      Func ChangeEmailStatus() ;******************************************************************************* ; changes the status of an email from unread to Read ;******************************************************************************* Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (Before Change)", $iRows) _OL_ItemModify($oOutlook,$aItems[$i][0], Default, "Read=True") MsgBox("", "Array Display 1", $aItems[1][0]) MsgBox("", "Array Display 2", $aItems[2][0]) Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (After Change)", $iRows) EndFunc  
    • nooneclose
      By nooneclose
      Hello again everyone, I am trying to make a simple bot/AI to help me at work. I need it to read the subject line of emails, open them if a certain subject line is found, and then copy the contents of the said email and paste it in a different program. 
      Can the Autoit outlook UDF help me achieve this? 
      Also, I have tried the Outlook UDF and so far I have only figured out how to find all the unread emails (thanks to one of water's example scripts. @water you are a genius just saying).
      I am very new to this UDF and would love any help that would guide me into making this bot/AI a reality at work.   
×