Borges Posted November 1, 2016 Share Posted November 1, 2016 Hello guy, I'm trying to send some emails "Default Emails" with a hotkey. For example: I'll press "pause" and will execute the code 1x (will send email) and stop. So, I'll select the other message and press "pause" again and will execute the code once more How can I stop that while to execute just 1x Thanks guys! here is my code atm: expandcollapse popup#include <MsgBoxConstants.au3> ; Press Esc to terminate script, Pause/Break to "pause" Global $g_bPaused = False HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") HotKeySet("+!d", "ShowMessage") ; Shift-Alt-d Local $Message = "Solicitação Atendida" Local $RespostaIcone = [290,83] Local $Title = "Tayna - Outlook" Local $EmailtoSend = [1033,790] Local $EmailRemove = [1295,195] Local $SendMessage = [934,298] Local $Send = [880,223] while 1 WinWaitActive($Title) MouseClick("left",$RespostaIcone[0], $RespostaIcone[1]) Sleep(2000) MouseClick("left",$EmailtoSend[0],$EmailtoSend[1]) Sleep(500) Send("^{c}") MouseClick("left", $EmailRemove[0],$EmailRemove[1]) Sleep(500) Send("{bs}") Sleep(500) Send("^{v}") Sleep(500) MouseClick("left",$SendMessage[0],$SendMessage[1]) Send($Message) sleep(500) MouseClick("left",$Send[0],$Send[1]) WEnd While 1 Sleep(100) WEnd Func TogglePause() $g_bPaused = Not $g_bPaused While $g_bPaused Sleep(100) ToolTip('Script is "Paused"', 0, 0) WEnd ToolTip("") EndFunc ;==>TogglePause Func Terminate() Exit EndFunc ;==>Terminate Func ShowMessage() MsgBox($MB_SYSTEMMODAL, "", "This is a message.") EndFunc ;==>ShowMessage Link to comment Share on other sites More sharing options...
water Posted November 1, 2016 Share Posted November 1, 2016 Welcome to AutoIt and the forum! Please have a look at ExitLoop in the help file. 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...
Borges Posted November 1, 2016 Author Share Posted November 1, 2016 ok, thank for that ExitLoop, and I found ContinueLoop also... but how can Continue this loop with a hotkey? here is my code now: expandcollapse popup#include <MsgBoxConstants.au3> ; Press Esc to terminate script, Pause/Break to "pause" Global $g_bPaused = False HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") HotKeySet("+!d", "ShowMessage") ; Shift-Alt-d Local $Message = "Solicitação Atendida" Local $RespostaIcone = [290,83] Local $Title = "Tayna - Outlook" Local $EmailtoSend = [1033,790] Local $EmailRemove = [1295,195] Local $SendMessage = [934,298] Local $Send = [880,223] while 1 WinWaitActive($Title) MouseClick("left",$RespostaIcone[0], $RespostaIcone[1]) Sleep(2000) MouseClick("left",$EmailtoSend[0],$EmailtoSend[1]) Sleep(500) Send("^{c}") MouseClick("left", $EmailRemove[0],$EmailRemove[1]) Sleep(500) Send("{bs}") Sleep(500) Send("^{v}") Sleep(500) MouseClick("left",$SendMessage[0],$SendMessage[1]) Send($Message) sleep(500) MouseClick("left",$Send[0],$Send[1]) ExitLoop WEnd While 1 Sleep(100) WEnd Func TogglePause() $g_bPaused = Not $g_bPaused While $g_bPaused Sleep(100) ToolTip('Script is "Paused"', 0, 0) WEnd ToolTip("") EndFunc ;==>TogglePause Func Terminate() Exit EndFunc ;==>Terminate Func ShowMessage() MsgBox($MB_SYSTEMMODAL, "", "This is a message.") EndFunc ;==>ShowMessage Link to comment Share on other sites More sharing options...
water Posted November 1, 2016 Share Posted November 1, 2016 Can you please tell me what's the purpose of your script? It seems you try to automate Outlook. There is an UDF available for Outlook which is much more stable than automating the Outlook GUI. 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...
Borges Posted November 1, 2016 Author Share Posted November 1, 2016 1 minute ago, water said: Can you please tell me what's the purpose of your script? It seems you try to automate Outlook. There is an UDF available for Outlook which is much more stable than automating the Outlook GUI. I receive alot of forms on my email (to register suppliers, delete applications etc..) and I need to reply all of them with "your request was done" So, I'm trying to do this with a hotkey... with this script it's working like a charm, but I'm trying to do with a hotkey. for example: press pause break in outlook and i'll send the message and script stops. So, I'll go to other email, complete the request and enable hotkey again to send another email to another person. Thanks for your time. Link to comment Share on other sites More sharing options...
Blue_Drache Posted November 1, 2016 Share Posted November 1, 2016 (edited) What I believe would be a better approach is a script that loops until a key is pressed, then calls a function to do your outlook thing. While 1 Sleep(10) If _IsPressed($key) Then FuncOutlookStuff() EndIf WEnd Func FuncOutlookStuff() ; stuff EndFunc ;==>FuncOutlookStuff This is how I would have approached it, building in safeguards and other exits as appropriate. Edited November 1, 2016 by Blue_Drache How do I put in AutoIt code now? Borges 1 Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
water Posted November 1, 2016 Share Posted November 1, 2016 I have written a similar script that encrypts attachments of the currently displayed mail by using the OutlookEX UDF. If you like I can post an example. 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...
Borges Posted November 1, 2016 Author Share Posted November 1, 2016 36 minutes ago, water said: I have written a similar script that encrypts attachments of the currently displayed mail by using the OutlookEX UDF. If you like I can post an example. I would like of corse. Link to comment Share on other sites More sharing options...
Borges Posted November 1, 2016 Author Share Posted November 1, 2016 1 hour ago, Blue_Drache said: What I believe would be a better approach is a script that loops until a key is pressed, then calls a function to do your outlook thing. While 1 Sleep(10) If _IsPressed($key) Then FuncOutlookStuff() EndIf WEnd Func FuncOutlookStuff() ; stuff EndFunc ;==>FuncOutlookStuff This is how I would have approached it, building in safeguards and other exits as appropriate. Thanks dude, Worked fine like this Link to comment Share on other sites More sharing options...
water Posted November 1, 2016 Share Posted November 1, 2016 Should the hotkey process the currently selected mail item in the folder or the currently displayed mail item? 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 November 2, 2016 Share Posted November 2, 2016 13 hours ago, Borges said: I would like of corse. This example grabs the currently displayed mail, creates a reply and inserts some text: #include <OutlookEX.au3> Global $sTitle = "Test" _ProcessMail() Func _ProcessMail() If ProcessExists("Outlook.exe") = 0 Then Return ; Outlook doesn't run $oOL = _OL_Open() ; Connect to Outlook If @error Then Return MsgBox($MB_ICONERROR, $sTitle, "Could not connect to Outlook!") $oInspector = $oOL.ActiveInspector() ; Get active Inspector window If @error Or Not IsObj($oInspector) Then Return MsgBox($MB_ICONERROR, $sTitle, "No open Inspector window found!") ; No open Inspector found $oItem = $oInspector.CurrentItem ; Access displayed item If @error Or Not IsObj($oItem) Or $oItem.Class <> $olMail Then Return ; Could not access displayed item or it is not a mail item $oReplyItem = _OL_ItemReply($oOL, $oItem) ; Create Reply item $oReplyItem.Body = "Your request was done" & @CRLF & @CRLF & $oReplyItem.Body ; Insert text into MailBody $oReplyItem.Display ; Display Reply item _OL_Close($oOL) EndFunc 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 November 2, 2016 Share Posted November 2, 2016 This example handles HTML and RTF correctly: #include <OutlookEX.au3> #include <Word.au3> Global $olEditorWord = 4 ; Microsoft Office Word editor Global $sTitle = "Test" _ProcessMail() Func _ProcessMail() If ProcessExists("Outlook.exe") = 0 Then Return ; Outlook doesn't run $oOL = _OL_Open() ; Could not connect to Outlook If @error Then Return MsgBox($MB_ICONERROR, $sTitle, "Could not connect to Outlook!") $oInspector = $oOL.ActiveInspector() ; Get active Inspector window If @error Or Not IsObj($oInspector) Then Return MsgBox($MB_ICONERROR, $sTitle, "No open Inspector window found!") ; No open Inspector found $oItem = $oInspector.CurrentItem ; Access displayed item If @error Or Not IsObj($oItem) Or $oItem.Class <> $olMail Then Return ; Could not access displayed item or it is not a mail item $oReplyItem = _OL_ItemReply($oOL, $oItem) ; Create the reply If $oOL.ActiveInspector.EditorType = $olEditorWord Then ; process HTML and RTF mails here $oReplyItem.Display $oReplyDoc = $oOL.ActiveInspector.WordEditor $oRange = _Word_DocRangeSet($oReplyDoc, -1) $oRange.InsertBefore("Your request was done!" & @CRLF & @CRLF) ; Insert the reply text Else $oReplyItem.Body = "Your request was done!" & $oReplyItem.Body $oReplyItem.Display EndIf _OL_Close($oOL) EndFunc ;==>_ProcessMail 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
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