Jump to content
Sign in to follow this  
water

OutlookEX UDF - Help & Support (II)

Recommended Posts

Neutro

Hey water, first thanks a lot to wooltown and you for this great UDF :)

I'm trying to find a way to automaticly export all Exchange offline data from an outlook profile to a .pst file for backup. So pretty much what Outlook is doing using the "Import/Export tool".

I looked at the manual of the function "_OL_ItemExport", and in the example is described a way to export to a .csv file but nothing about .pst :(

Is it possible to do this using your UDF?

Thanks in advance for your help :)

Share this post


Link to post
Share on other sites
water

_OL_ItemExport is used to write items to the file system. You want to write items to another store (PST file) so _OL_ItemCopy is what you are looking for.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Neutro

Well I'm having a hard time trying to get it working >_<

So if I understand correctly I need to copy every items of every folders of the exchange store to a pst file using OL_Item_Copy?

If so, how can i get a list of all folders of a store?

I tried using:

OL_FolderFind($oOutlook, "\\path_to_exchange_store", 99,"","",$olMailItem)

but the returned array is empty :

#Edit: nevermind, i just found out about OL_FolderTree on previous forum page :sweating:

I'll try to get this working now :D

Edited by Neutro

Share this post


Link to post
Share on other sites
water

So if I understand correctly I need to copy every items of every folders of the exchange store to a pst file using OL_Item_Copy?

Correct. Unfortunately there is no function available to do what you need with a single call. Maybe an example can be created later.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Neutro

Woot I finally managed to do what I wanted like this:
 

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

SplashTextOn("Please wait","Mailbox sync in progress." & @CRLF & @CRLF & "If a window asking for your ID and password pops-up," & @CRLF & "please enter them and click on OK." & @CRLF & @CRLF & "Once you entered your ID and password or if they were not asked," & @CRLF & "please do not use your computer while this window is showing." & @CRLF & @CRLF & "Sync time is approximatively around 1 min.",600,215,-1,-1,18)

$outlook = _OL_Open(True)

sleep(2000)

$pst = _OL_PSTCreate($outlook, @UserProfileDir & "\exchangebackup\exchangebackup.pst", "Exchange backup ")

sleep(2000)

_OL_ItemSync($Outlook)

_OL_ItemSendReceive($Outlook)

$folders = _OL_FolderTree($outlook, "*") ;first use of FolderTree is needed to force sync with Exchange server

sleep(30000) ; giving 30s to the client to sync items with the Exchange server

SplashTextOn("Please wait","Mailbox backup in progress." & @CRLF & @CRLF & "If a window asking for your ID and password pops-up," & @CRLF & "please enter them and click on OK." & @CRLF & @CRLF & "Once you entered your ID and password or if they were not asked," & @CRLF & "please do not use your computer while this window is showing." & @CRLF & @CRLF & "Backup time depends on how large your mailbox is.",600,215,-1,-1,18)

$folders = _OL_FolderTree($outlook, "*", 2)

If IsArray($folders) then 

   for $i = 2 to UBound($folders) - 1 step 1
      
      if stringinstr(stringmid($folders[$i], 3), stringmid($folders[0], 3)) <> 0 then

         $current_folder = _OL_FolderAccess($outlook, stringmid($folders[$i], 3))

          if IsArray($current_folder) then _OL_FolderCopy($outlook, $current_folder[1], $pst)
 
        endif

    next

endif

_OL_Close($outlook)

SplashOff()

I was going to say "Thanks again for your help Water", but since i'm saying this like almost every time i need help here, I added it to my signature so I don't need to write it everytime now :D

I noticed something strange while developping this: the _OL_FolderTree will work perfectly if used on an Outlook client on which the user is already logged on or in offline mode, but if used when the Outlook client is in a state of needed user authentification (this happens when you click on "cancel" when asked for login/password for exchange account), then one of the array row will be blank.

That's why i included a check in the above script so if the folder name does not include user root folder inside, it won't try to copy it.

Edited by Neutro

Share this post


Link to post
Share on other sites
water

Hi Neutro,

thanks for adding me to your signature :)

If the user "clicks on 'cancel' when asked for login/password for exchange account" _OL_Open should return an error because logon wasn't successful.

Can you please check the value of @error after _OL_Open?

BTW: Which version of Outlook do you run?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Neutro

@error value is 0.

Also I noticed that the Exchange credential window pops up only when _OL_FolderTree is called, not just after _OL_Open().

I tried it on Outlook 2010 and 2013.

Share this post


Link to post
Share on other sites
water

Could you please try this stripped down script? I tested _OL_FolderTree here and it works jsut fine.

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

SplashTextOn("Please wait", "Mailbox sync in progress." & @CRLF & @CRLF & "If a window asking for your ID and password pops-up," & @CRLF & "please enter them and click on OK." & @CRLF & @CRLF & "Once you entered your ID and password or if they were not asked," & @CRLF & "please do not use your computer while this window is showing." & @CRLF & @CRLF & "Sync time is approximatively around 1 min.", 600, 215, -1, -1, 18)
$outlook = _OL_Open(True)
If @error Then Exit MsgBox(0, "Error", "_OL_Open: @error = " & @error & ", @extended = " & @extended)

$pst = _OL_PSTCreate($outlook, @UserProfileDir & "\exchangebackup\exchangebackup.pst", "Exchange backup")
If @error Then Exit MsgBox(0, "Error", "_OL_PSTCreate: @error = " & @error & ", @extended = " & @extended)

SplashTextOn("Please wait", "Mailbox backup in progress." & @CRLF & @CRLF & "If a window asking for your ID and password pops-up," & @CRLF & "please enter them and click on OK." & @CRLF & @CRLF & "Once you entered your ID and password or if they were not asked," & @CRLF & "please do not use your computer while this window is showing." & @CRLF & @CRLF & "Backup time depends on how large your mailbox is.", 600, 215, -1, -1, 18)

$folders = _OL_FolderTree($outlook, "*")
If @error Then Exit MsgBox(0, "Error", "_OL_FolderTree: @error = " & @error & ", @extended = " & @extended)
For $i = 2 To UBound($folders) - 1 Step 1
If StringInStr(StringMid($folders[$i], 3), StringMid($folders[0], 3)) <> 0 Then
$current_folder = _OL_FolderAccess($outlook, StringMid($folders[$i], 3))
If @error Then Exit MsgBox(0, "Error", "_OL_FolderAccess for folder: " & $folders[$i] & ". @error = " & @error & ", @extended = " & @extended)
_OL_FolderCopy($outlook, $current_folder[1], $pst)
If @error Then Exit MsgBox(0, "Error", "_OL_FolderCopy for folder: " & $folders[$i] & ". @error = " & @error & ", @extended = " & @extended)
EndIf
Next
_OL_Close($outlook)
SplashOff()

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Neutro

The above code will not sync Outlook with the exchange server before making the copy of the folders even if you enter the correct credentials.

For this to work, I need to use a first _OL_FolderTree that will open the credential window, then wait 30s so the outlook client has enough time to sync with the server, then use _OL_FolderTree again to get the updated folder list. But that is not a problem since it's still working this way.

What I could need is a way to find out if a user pressed cancel on the authentication window or not.

Share this post


Link to post
Share on other sites
water

I removed the sync part because I wanted to have a simple reproducer. If copying the folders to a PST works then we can add the sync part again.

My above example doesn't sync but does it do the copy job correct?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

Fine. So we now need a way to connect to Exchange and get the latest mails before we start the backup.

Looks like _OL_SendReceive should do this according to microsoft. So _OL_ItemSync is not necessary.

If you manually run Outlook in online mode do you need to enter userid/password as well?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Neutro

No, as well as if I check the box "remember ID" after one login.

I tried using _OL_SendReceive and _OL_Sync before using _OL_TreeView but it doesn't do much.

Share this post


Link to post
Share on other sites
water

You could try and provide the password with _OL_Open as 6th parameter.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Vernie

Hay there folks :)

When i run my script from Scite editor it works like a charm.

but when i try to send an email after i compiled my program i get the error.

error create connection to outlook @error =1, extended = -2146959355

It is driving me nuts..

Below a part of my script..

GUICreate("Feature Request", 633, 447, 192, 124)
$Edit1 = GUICtrlCreateEdit("", 32, 24, 569, 353)
GUICtrlSetData(-1, "")
$OK = GUICtrlCreateButton("OK", 32, 400, 113, 25, $WS_GROUP)
$CANCEL = GUICtrlCreateButton("Cancel", 480, 400, 121, 25, $WS_GROUP)


Case $requestform

Switch $msg[0]
Case $GUI_EVENT_CLOSE
GUIDelete($requestform)
GUISetState(@SW_SHOW, $mainform)
Case $OK
Call ("SendRequest")


GUIDelete($requestform)
GUISetState(@SW_SHOW, $mainform)
Case $CANCEL
GUIDelete($requestform)
GUISetState(@SW_SHOW, $mainform)
EndSwitch
EndSwitch

WEnd


Func SendRequest()

$oOL = _OL_Open()
If @error <> 0 Then Exit MsgBox(16, "Test", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended)
$sTo = "me@domain.nl"
$sSubject = "Subject program x"
$sBody = (GUICtrlRead($Edit1) & @CRLF)
If @error = 1 Then Exit
_OL_Wrapper_SendMail($oOL, $sTo, "", "", $sSubject, $sBody)
If @error <> 0 Then MsgBox(16, "Test", "Error sending mail. @error = " & @error & ", @extended: " & @extended)
_OL_Close($oOL)

endfunc

Share this post


Link to post
Share on other sites
water

Welcome to AutoIt and the forum!

Can you please tell me wich Operating System (Windows 7, Windows XP ...), which version of Outlook and which version of AutoIt you run ?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Vernie

Thnx for the warm welcome..

I have installed SciTe version 3.3.0 with autoit V3

We are using windows 8 x64 with outlook 2013.

Share this post


Link to post
Share on other sites
water

Do you run the 32bit or 64bit version of Outlook 2013?

I run my scripts on WIndows 7 64bit and Office 2010 32bit without problems.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
Vernie

Im running the 2013 32 bits version...

The weird thing is that the error only occurs after i compiled to a executable.

im installing office 2010 on my virtual machine and will test the exectuble in the virtual box.

Share this post


Link to post
Share on other sites
Vernie

Ok i've tested in on my virtual box with Windows 7 64 bits and outlook 2010 (both 64 and 32 bits).

Both are working without any problems.

seems that my programs has a problem with outlook 2013 or windows 8

Edited by Vernie

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×