water Posted March 7, 2013 Author Share Posted March 7, 2013 Have you tried the _OL_ItemCreate.au3 example script? Does this work for you? 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 7, 2013 Share Posted March 7, 2013 I just tested it. It works when Outlook is open. But if run when outlook is not open, I get the following error: Error creating the test environment. @error = 508, @extended = 2 Link to comment Share on other sites More sharing options...
water Posted March 8, 2013 Author Share Posted March 8, 2013 Very strange. Which version of AutoIt do you run (I'm sure I've asked this in the past too)? 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 8, 2013 Share Posted March 8, 2013 AutoIT Version 3.3.8.1 Link to comment Share on other sites More sharing options...
water Posted March 9, 2013 Author Share Posted March 9, 2013 SkoubyWan, I can reproduce the error. I get: COM Error Encountered in OL_Test5.au3 OutlookEx UDF version = 0.9.1 @AutoItVersion = 3.3.8.1 @AutoItX64 = 0 @Compiled = 0 @OSArch = X64 @OSVersion = WIN_7 Scriptline = 2442 NumberHex = 800706BE Number = -2147023170 WinDescription = Remote Procedure Call failed Description = Source = HelpFile = HelpContext = 1027423549 LastDllError = 0It's not obvious to me what happens so some testing will be needed ... 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 9, 2013 Author Share Posted March 9, 2013 I think I found the bug. Please replace line $oItem.Close(0)in function _OL_ItemCreate with$oItem.Save() 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 9, 2013 Share Posted March 9, 2013 Great! That solved the problem. Now I just have to solve a problem in my own programing since the WinWaitClose("Message (HTML)") doesn't cause the program to wait. The email flashes on the screen and then is gone due to the _OL_Close command. But this one I can probably figure out on my own. Thanks so much for your efforts. This is an indispensable UDF. Link to comment Share on other sites More sharing options...
SkoubyeWan Posted March 9, 2013 Share Posted March 9, 2013 Great! That solved the problem. Now I just have to solve a problem in my own programing since the WinWaitClose("Message (HTML)") doesn't cause the program to wait. The email flashes on the screen and then is gone due to the _OL_Close command. But this one I can probably figure out on my own. Thanks so much for your efforts. This is an indispensable UDF. Here is the solution to my prior programming error: Needed to be able to match substrings. Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase Link to comment Share on other sites More sharing options...
SkoubyeWan Posted March 9, 2013 Share Posted March 9, 2013 A follow up from my prior post. Adding Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase solved the disappearing email problem. Now I get no errors and it waits for me to hit the send button on the created email. But hitting the send button immediately closes outlook and the email must wait in the outbox until outlook is opened again to send it. I tried adding the _OL_ItemSendReceive but since outlook is closed, it gives an error. I can solve the problem by opening outlook again after the WinWaitClose statement, but that seems inelegant. Is there a way to click send on the created email item and keep outlook open for the sendreceive function? Or better yet, just have outlook not close until that email is sent. Here is the code for this function. Thanks for any input. 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) _OL_ItemDisplay($oOutlook, $oItem) WinWaitClose("Message (HTML)") Global $oOutlook = _OL_Open() _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) Link to comment Share on other sites More sharing options...
water Posted March 9, 2013 Author Share Posted March 9, 2013 A second _OL_Open isn't needed because Outlook stays open in the background until _OL_Close is called. So the script should look like: 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) _OL_ItemDisplay($oOutlook, $oItem) Opt("WinTitleMatchMode", 2) WinWaitClose("Message (HTML)") _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 9, 2013 Share Posted March 9, 2013 I agree that the second _OL_Open should not be necessary. But without it your script gives me this error: Error sending/receiving mail. @error = 99, @extended = 12. It appears that Outlook closes when the "Send" key is hit in the email. I guess that is really what I am asking. How do I avoid this. Again, there is no problem if the full version of Outlook is open in the background, but without it, you have to open Outlook again using _OL_Open and then send and receive. I am assuming you are not having this error occur. I seem to be the problem lately. I am running Outlook 2010, Windows XP SP3, and AutoIT Version 3.3.8.1. Link to comment Share on other sites More sharing options...
water Posted March 9, 2013 Author Share Posted March 9, 2013 Error 99 means: Function not available for this Outlook version. @extended denotes the lowest required Outlook version to run the function But you are running version 14 so everything should be fine. Looks like some kind of bug - again Will again do some testing and come back as soon as I know what's going on. 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 10, 2013 Share Posted March 10, 2013 I don't know if this information helps or not, but when I hit the send button on the email, the Outlook icon in the systems tray goes away. This is what I mean by saying that hitting the send button shuts down Outlook. Link to comment Share on other sites More sharing options...
water Posted March 10, 2013 Author Share Posted March 10, 2013 Very, very strange. Google didn't find anything so I need to test when I'm in my office again. 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 10, 2013 Author Share Posted March 10, 2013 Strange problem. As soon as the displayed item is closed, Outlook closes too. Has nothing to do with _OL_ItemDisplay because the following script acts the same way. It waits for 5 seconds then calls _OL_ItemSendRecieve. If you manually close the displayed item before the 5 seconds have passed then _OL_ItemSendRecieve will return @error = 99, else it works as expected. #include <OutlookEX.au3> Opt("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) $BodyFinalWithLink = "Body" $SubjectFinal = "Subject" $StaffEmail = "name@company.com" Global $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) $oItem.Display() Sleep(5000) _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 11, 2013 Share Posted March 11, 2013 Clearly you have been able to reproduce the issue i am having. I cannot make sense of why this happens either. I would have expected Outlook to remain active after closing the email item. The short term work around is to place another $oOutlook = _OL_Open() statement just before the send and receive to assure that Outlook sends the email. Thanks for looking into this. Link to comment Share on other sites More sharing options...
water Posted March 11, 2013 Author Share Posted March 11, 2013 (edited) I too would expect Outlook to remain active. I replaced $oItem.Display() with $oItem.GetInspector.Activate() because .Display is only still valid for cmpatibility reasons. But the result is the same.According to MS Outlook is closed when there is no more open window.So the script should look like: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) WinWaitClose("Message (HTML)") _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) 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...
water Posted March 12, 2013 Author Share Posted March 12, 2013 I tested the above script and it works - Outlook stays open in the background. Could you please test too? 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 Sorry for the slow response. I have been out of pocket for a few days. I tested the above code as well, and as you said, outlook does stay open to send the message when the send button is pressed on the email. However, the script never comes to an end to close outlook either. In other words, the script doesn't execute any further past the showing of the email item. It never gets to executing the send receive, it just does a send receive because outlook stays open, but it never does get to closing outlook and I have to manually end the script. If I comment out the new line ($oExplorer = $oItem.Parent.GetExplorer), then it goes back to the prior error message and outlook closing on hitting the send button. So I guess we have solved one problem but created another. Why doesn't the script continue to execute after the _OL_ItemDisplay command? Link to comment Share on other sites More sharing options...
water Posted March 16, 2013 Author Share Posted March 16, 2013 Could you please addAutoItSetOption("TrayIconDebug", 1)at the top of the script? If you then run your script from SciTE and move the mouse over the AutoIt symbol in the system tray a tooltip displays the statement where the script has stopped. 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