SkoubyeWan Posted March 16, 2013 Share Posted March 16, 2013 (edited) It stopped on the WinWaitClose("Message (HTML)") statement. If I comment out the $oExplorer = $oItem.Parent.GetExplorer statement then it continues execution on the closing of the window as it should. However, I am then back to the original problem that the email is not sent immediately as I want and I get the error. Edited March 16, 2013 by SkoubyeWan Link to comment Share on other sites More sharing options...
water Posted March 16, 2013 Author Share Posted March 16, 2013 Strange. The window is closed but Windows still thinks the window exists. That's even true when I check the Inspector via Outlook COM. 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...
water Posted March 16, 2013 Author Share Posted March 16, 2013 (edited) Looks like that's the way Outlook works. It keeps items as long as it thinks they are needed.I see no workaround at the moment. Edited March 16, 2013 by water 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...
SkoubyeWan Posted March 16, 2013 Share Posted March 16, 2013 (edited) Yes. I see what you are saying. While outlook stays open, it keeps thinking the window is open. My prior workaround is working well so far. That is, I re-open outlook just before the send and receive. Not elegant or efficient but effective. Edited March 16, 2013 by SkoubyeWan Link to comment Share on other sites More sharing options...
water Posted March 16, 2013 Author Share Posted March 16, 2013 The Window still exists because it has been closed by the user but not yet been released by Outlook. 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...
water Posted March 16, 2013 Author Share Posted March 16, 2013 I think I got it. Replace the code after _OL_ItemDisplay with this lines:Opt("WinTitlematchmode", 2) While 1 If WinGetState("Message (HTML)") = 5 Then ExitLoop Sleep(250) WEnd ConsoleWrite("Window closed!" & @LF) _OL_ItemSendReceive($oOutlook, False) If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemSendReceive Example Script", "Error sending/receiving mail. @error = " & @error & ", @extended = " & @extended) MsgBox(64, "OutlookEX UDF: _OL_ItemSendReceive Example Script", "Mail successfully sent/received!") _OL_Close($oOutlook) 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...
SkoubyeWan Posted March 16, 2013 Share Posted March 16, 2013 It does appear to work until I comment out the MsgBox saying that the message was successfully sent and received. Then I get an error from outlook that there are items in the outbox that will not be sent if outlook is exited. It appears that the msgbox causes a large enough delay so that the email gets sent before the script closes the connection to Outlook. So, I then tried adding a Sleep (25000) in place of the msgbox, and the script still works. I then added some code to make script wait until the outbox is empty, and then close outlook. This seems to work. Here is the code. I would welcome any improvements. Thanks for your help. #include AutoItSetOption("TrayIconDebug", 1) Global $oOutlook = _OL_Open() If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended) $oItem = _OL_ItemCreate($oOutlook, $olMailItem, "", "", "", "BodyFormat=" & $olFormatHTML);, "Body=" & $BodyFinalWithLink, "Subject=" & $SubjectFinal, "To=" & $StaffEmail, "Importance=" & $olImportanceHigh) If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemCreate Script", "Error creating mail. @error = " & @error & ", @extended = " & @extended) $oExplorer = $oItem.Parent.GetExplorer _OL_ItemDisplay($oOutlook, $oItem) Opt("WinTitlematchmode", 2) While 1 If WinGetState("Message (HTML)") = 5 Then ExitLoop Sleep(250) WEnd ;Checks Outobox folder for items not yet sent Global $aResult = _OL_FolderGet($oOutlook, "*\Outbox") If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_FolderGet Example Script", "Error accessing current folder. @error = " & @error & ", @extended = " & @extended) ;_ArrayDisplay($aResult, "OutlookEX UDF: properties of the current folder") ;While Outbox has items, continue the script, checking every second While $aResult[8] <> 0 $aResult = _OL_FolderGet($oOutlook, "*\Outbox") If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_FolderGet Example Script", "Error accessing current folder. @error = " & @error & ", @extended = " & @extended) ;_ArrayDisplay($aResult, "OutlookEX UDF: properties of the current folder") Sleep(1000) WEnd _OL_Close($oOutlook) Link to comment Share on other sites More sharing options...
water Posted March 16, 2013 Author Share Posted March 16, 2013 Strange.According to MSDN "Calling the SendAndReceive method is synchronous". So the method only returns when all mails have been sent/received.BTW: Where do you call _OL_ItemSendReceive in the code you posted above? 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...
SkoubyeWan Posted March 16, 2013 Share Posted March 16, 2013 I didn't. I found that outlook automatically does a send and receive when the Send button is pressed, as long as outlook remains open long enough to accomplish the task. I had added the send and receive only because outlook would close when the Send button was pressed and I had to reopen outlook and then send the item. thanks to your code, outlook stays open, and my modification makes sure it doesn't try to close until after the outbox is empty. Link to comment Share on other sites More sharing options...
water Posted March 16, 2013 Author Share Posted March 16, 2013 As SendAndReceive is synchronous you can replace the code where you check the Outbox by a single call to _OL_ItemSendReceive. 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...
SkoubyeWan Posted March 16, 2013 Share Posted March 16, 2013 (edited) That was what we tried before, but the script tries to close outlook before the send and receive is complete and i get an error from outlook informing me that there are items in my outbox and they will not be sent if outlook is closed. A timer then starts counting down. This was the reason for having the outbox check language added. Edited March 16, 2013 by SkoubyeWan Link to comment Share on other sites More sharing options...
water Posted March 16, 2013 Author Share Posted March 16, 2013 Premature closure of Outlook should be prevented by$oExplorer = $oItem.Parent.GetExplorer 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...
SkoubyeWan Posted March 16, 2013 Share Posted March 16, 2013 That does stop the pressing of the Send button on the email from closing outlook, but it does not appear to stop the _OL_Close($oOutlook) command from trying to close outlook before the outbox is empty. Link to comment Share on other sites More sharing options...
water Posted March 16, 2013 Author Share Posted March 16, 2013 That's correct. To solve this problem you need to call _OL_ItemSendReceive in addition. 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...
SkoubyeWan Posted March 16, 2013 Share Posted March 16, 2013 Okay. I found the problem. When this code is run as you proposed, the script ends trying to close before the outbox is empty. I receive an error message from outlook saying there are items in my outbox that have not been sent and if i close now they will not be sent. then a timer begins to count down. Apparently the timing between the send and receive and the saving of the email to the outbox is too quick so that the item is saved to the outbox effectively after the send and receive is already complete. By adding a Sleep(1000) before the send and receive is run, allowing time for the sent time to be posted to the outbox, the script performs correctly. Here is the finished script. #include AutoItSetOption("TrayIconDebug", 1) Global $oOutlook = _OL_Open() If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended) $oItem = _OL_ItemCreate($oOutlook, $olMailItem, "", "", "", "BodyFormat=" & $olFormatHTML);, "Body=" & $BodyFinalWithLink, "Subject=" & $SubjectFinal, "To=" & $StaffEmail, "Importance=" & $olImportanceHigh) If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OL_ItemCreate Script", "Error creating mail. @error = " & @error & ", @extended = " & @extended) $oExplorer = $oItem.Parent.GetExplorer _OL_ItemDisplay($oOutlook, $oItem) Opt("WinTitlematchmode", 2) While 1 If WinGetState("Message (HTML)") = 5 Then ExitLoop Sleep(250) WEnd sleep (1000) _OL_ItemSendReceive($oOutlook, False) _OL_Close($oOutlook) Link to comment Share on other sites More sharing options...
water Posted March 16, 2013 Author Share Posted March 16, 2013 I'm glad the problem could be solved. I have now a better understanding of what goes on behind the scenes. Looks like this information can only be gathered by trial and error. Google doesn't help much. 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...
SkoubyeWan Posted March 16, 2013 Share Posted March 16, 2013 Nice to have someone to bounce ideas off of. Thank you for your invaluable help. Link to comment Share on other sites More sharing options...
water Posted March 16, 2013 Author Share Posted March 16, 2013 Glad to be of service 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...
shaime Posted March 18, 2013 Share Posted March 18, 2013 Hey all, I tried, and succeeded, to send a new email automatically. Now i'm looking to use some 'add in' which is in the new email window, and cant find the way to access it. I've tried to search how to access the ribbon/pane/tabs/.... but with no luck (Searched google, msdn, tried to figure out the outlook object model...) Does some one knows what is the right way of doing it? Actually the best as for me is to get access to the add in itself (i thought it will look like xml formatted with all 'children' attached to the 'add in' and such, is it?) Thank you all!! BTW: water, thanks A LOT for the OutlookEx, it really helped me get started the whole thing goin'.. Link to comment Share on other sites More sharing options...
water Posted March 18, 2013 Author Share Posted March 18, 2013 Welcome to AutoIt and the forum! I've never used it before but it looks like you can access the installed add ins. I'm not in my office at the moment. I will try again tomorrow. Can you post the name of the add in and - if possible - which methods and properties the add in provides? 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...
Recommended Posts