Jump to content
tweakster2010

ControlSend, sending email instead of text

Recommended Posts

tweakster2010

Hey Guys,

 

I am trying to use controlsend over using send keys for an e-mail to contact teams(reason I am doing this instead of the outlook UDF is the outlook UDF is either above my mentality right now or with our setup does not approve of the attempts on the exchange).

That being said send works fine but I am wanting to be a little more concise and less user error possibilities so I was setting up to use controlsend. But what I noticed is the Body fo a new E-mail has this class [CLASS:_WwG; INSTANCE:1] which when I do a ControlSend to same said class it sends the e-mail instead of trying to send the text to the Body of the E-mail. The Button to send is [CLASS:Button; INSTANCE:1] so I am not understanding how ControlSend is mixing up the classes. Here is what I have code wise for it.

This is what is being used and works for me right now.

WinActivate ("Microsoft Outlook")
    Sleep(500)
    Send("!h")
    Send("n")
    Sleep(500)
            If _IsChecked($eg1) = True Then
                Send("emailgroup1" & ";")
            EndIf
            If _IsChecked($eg2) = True Then
                Send("emailgroup2" & ";")
            EndIf
            If _IsChecked($eg3) = True Then
                Send("emailgroup3" & ";")
            EndIf
            If _IsChecked($eg4) = True Then
                Send("emailgroup4" & ";")
            EndIf
            If _IsChecked($eg5) = True Then
                Send("emailgroup5" & ";")
            EndIf
            If _IsChecked($eg6) = True Then
                Send("emailgroup6" & ";")
            EndIf
            If _IsChecked($eg7) = True Then
                Send("emailgroup7" & ";")
            EndIf
            If _IsChecked($eg8) = True Then
                Send("emailgroup8" & ";")
            EndIf
            If _IsChecked($eg9) = True Then
                Send("emailgroup9" & ";")
            EndIf
            If _IsChecked($eg10) = True Then
                Send("emailgroup10" & ";")
            EndIf
    Sleep(2000)
    Send("{TAB 2}")
    Sleep(1000)
    Send(GuiCtrlRead($TitleofEmail))
    Sleep(1500)
    Send("{TAB}")
    Sleep(500)
    Send(GuiCtrlRead($BodyofEmail))
    Sleep(4000)
    Send("!s")

            GuiDelete($EmailSupport)
            Return

This is what I am having a problem with

; original subject and body with Send
;   Sleep(2000)
;   Send("{TAB 2}")
;   Sleep(1000)
;   Send(GuiCtrlRead($TitleofEmail))
;   Sleep(1500)
;   Send("{TAB}")
;   Sleep(500)
;   Send(GuiCtrlRead($BodyofEmail))
;   Sleep(4000)
;   Send("!s")

;removed send at end to test placing text first.
ControlSend("Untitled","","[CLASS:RichEdit20WPT;INSTANCE:4]",GuiCtrlRead($TitleofEmail))
Sleep(500)
ControlSend("Untitled","","[CLASS:_WwG; INSTANCE:1]",GuiCtrlRead($BodyofEmail))

When Controlsend to _WwG kicks off it sends the email instead. Gets very glitchy on how it interacts with it.

 

Any Idea?

Share this post


Link to post
Share on other sites
topten

You might have mess with your $variables or controls you are reading. Just check if you are getting into variable what you expect to

$var = GuiCtrlRead($TitleofEmail)

msgbox (0, "Var from title of email", $var )

$var2 = GuiCtrlRead($BodyofEmail)

msgbox (0, "Var from Body of email", $var2 )

Share this post


Link to post
Share on other sites
tweakster2010

The Variables work on Send but not ControlSend, I think its the way the class is being hit. 

Here is the GUI its being called from.

I have changed the actual groups to leave out proprietary info >.>

$EmailSupport = GUICreate("Email Support", 578, 494, 220, 158)
    GUISetBkColor(0x008080)
    ;Check Boxes
    $AssetE = GUICtrlCreateCheckbox("emailgroup1", 8, 8, 145, 17)
    $ComputerE = GUICtrlCreateCheckbox("emailgroup2", 8, 24, 105, 17)
    $CSSDRi = GUICtrlCreateCheckbox("emailgroup3", 8, 40, 97, 17)
    $CSSDRetail = GUICtrlCreateCheckbox("emailgroup4", 8, 56, 97, 17)
    $CSSD = GuiCtrlCreateCheckbox("emailgroup5", 8,72,97,17)
    $RIT = GuiCtrlCreateCheckbox("emailgroup6",160,72,97,17)
    $Firewall = GUICtrlCreateCheckbox("emailgroup7", 160, 8, 105, 17)
    $ITCC = GUICtrlCreateCheckbox("emailgroup8", 160, 24, 97, 17)
    $Message = GUICtrlCreateCheckbox("emailgroup9", 160, 40, 97, 17)
    $Wireless = GUICtrlCreateCheckbox("emailgroup10", 160, 56, 129, 17)
    ;Input fields in UI
    $TitleofEmail = GUICtrlCreateInput("", 8, 90, 553, 21)
    $BodyofEmail = GUICtrlCreateEdit("Problem:" & @CRLF & "Description of problem:" & @CRLF & "Issue began:" & @CRLF & "Error message:" & @CRLF & "Steps taken:" & @CRLF & "Asset tag:" & @CRLF & "Location:" & @CRLF & "OS:" & @CRLF & "Extension and/or Cell:" , 8, 120, 561, 329, BitOR($ES_WANTRETURN, $WS_VSCROLL))
    ;Buttons in UI
    $EmailSubmit = GUICtrlCreateButton("Submit", 152, 448, 75, 25)
    $emailexit = GUICtrlCreateButton("Exit", 248, 448, 75, 25)
    GuiSetState(@SW_Show)

 

The Variables work on Send but not ControlSend, I think its the way the class is being hit. 

Here is the GUI its being called from.

I have changed the actual groups to leave out proprietary info >.>

$EmailSupport = GUICreate("Email Support", 578, 494, 220, 158)
    GUISetBkColor(0x008080)
    ;Check Boxes
    $AssetE = GUICtrlCreateCheckbox("emailgroup1", 8, 8, 145, 17)
    $ComputerE = GUICtrlCreateCheckbox("emailgroup2", 8, 24, 105, 17)
    $CSSDRi = GUICtrlCreateCheckbox("emailgroup3", 8, 40, 97, 17)
    $CSSDRetail = GUICtrlCreateCheckbox("emailgroup4", 8, 56, 97, 17)
    $CSSD = GuiCtrlCreateCheckbox("emailgroup5", 8,72,97,17)
    $RIT = GuiCtrlCreateCheckbox("emailgroup6",160,72,97,17)
    $Firewall = GUICtrlCreateCheckbox("emailgroup7", 160, 8, 105, 17)
    $ITCC = GUICtrlCreateCheckbox("emailgroup8", 160, 24, 97, 17)
    $Message = GUICtrlCreateCheckbox("emailgroup9", 160, 40, 97, 17)
    $Wireless = GUICtrlCreateCheckbox("emailgroup10", 160, 56, 129, 17)
    ;Input fields in UI
    $TitleofEmail = GUICtrlCreateInput("", 8, 90, 553, 21)
    $BodyofEmail = GUICtrlCreateEdit("Problem:" & @CRLF & "Description of problem:" & @CRLF & "Issue began:" & @CRLF & "Error message:" & @CRLF & "Steps taken:" & @CRLF & "Asset tag:" & @CRLF & "Location:" & @CRLF & "OS:" & @CRLF & "Extension and/or Cell:" , 8, 120, 561, 329, BitOR($ES_WANTRETURN, $WS_VSCROLL))
    ;Buttons in UI
    $EmailSubmit = GUICtrlCreateButton("Submit", 152, 448, 75, 25)
    $emailexit = GUICtrlCreateButton("Exit", 248, 448, 75, 25)
    GuiSetState(@SW_Show)

 

Share this post


Link to post
Share on other sites
topten

If I understand you correct, one and the same variable works ok, when you are using SEND, but when you are using controlsend it gives different result?

Share this post


Link to post
Share on other sites
water

Using the OutlookEX UDF only fails when you run a trial version of Outlook or have upgraded from a trial version.
Everything else might be a problem with the script and should be "easy" to fix ;)


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
topten
ControlSend("Untitled","","[CLASS:RichEdit20WPT;INSTANCE:4]",GuiCtrlRead($TitleofEmail))
Sleep(500)
ControlSend("Untitled","","[CLASS:_WwG; INSTANCE:1]",GuiCtrlRead($BodyofEmail))

It means that the CLASS or INSTANCE is messed there, You should try another instance perhaps What does Your Autoit Info tool show when you are examining the controls?

Share this post


Link to post
Share on other sites
tweakster2010
;Subject line works
ControlSend("Untitled","","[CLASS:RichEdit20WPT;INSTANCE:4]",GuiCtrlRead($TitleofEmail))
Sleep(500)
;edit box class and instance
ControlSend("Untitled","","[CLASS:_WwG; INSTANCE:1]",GuiCtrlRead($BodyofEmail))

The Send Button shows as 

[CLASS:Button; INSTANCE:1]

The main class shows as rctrl_renwnd32 for the untitled window, which i dont call at all.

;Subject line works
ControlSend("Untitled","","[CLASS:RichEdit20WPT;INSTANCE:4]",GuiCtrlRead($TitleofEmail))
Sleep(500)
;edit box class and instance
ControlSend("Untitled","","[CLASS:_WwG; INSTANCE:1]",GuiCtrlRead($BodyofEmail))

The Send Button shows as 

[CLASS:Button; INSTANCE:1]

The main class shows as rctrl_renwnd32 for the untitled window, which i dont call at all.

Share this post


Link to post
Share on other sites
tweakster2010

Surprisingly development, controlsend works if I tab to the body of the email. So its a funny interaction indeed with where the cursor is defaulted. Where as the inputs work but i also noticed the inputs  like TO,CC,BCC,Subject all have IDs but the body does not. Maybe its by design its limited. But either way I know at this point I would have to tab to the part to insert the body but I can controlsend the rest no issue. Just odd. I am still going to play around with it trying to find a way to get it to where I dont have to tab to it.

Surprisingly development, controlsend works if I tab to the body of the email. So its a funny interaction indeed with where the cursor is defaulted. Where as the inputs work but i also noticed the inputs  like TO,CC,BCC,Subject all have IDs but the body does not. Maybe its by design its limited. But either way I know at this point I would have to tab to the part to insert the body but I can controlsend the rest no issue. Just odd. I am still going to play around with it trying to find a way to get it to where I dont have to tab to it.

Share this post


Link to post
Share on other sites
water

Don't you think it would be easier to automate Outlook by COM (OutlookEX UDF) than to automate the GUI?
Which problems did you face when using the UDF?


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
tweakster2010

I honestly couldnt tell you anymore, I will have to set it up again and see what happens for me.

 

Share this post


Link to post
Share on other sites
water

Just grab the OutlookEX zip file, extract it to a test directory. In this directory create the following script:

#include <OutlookEX.au3>
$oOL = _OL_Open()
msgBox(0, "Result", "@error = " & @error)

If @error = 0 then the rest should be easy.


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
tweakster2010

@error = 1. This is error I receive, now here is another catch. The program I am running it through goes through administrator rights and elevated rights while my primary account does not have said rights(so I log in and elevate). Where if I run it without admin rights it works fine and reports @error = 0.

Do you have a possible solution for that or workaround built in because of that type of scenario might be pretty common in a work environment? :)

 

PS (EDIT)

 

Maybe I can strip out my Email portion and compile it into its own .exe and just do a shellexecute for it independantly... I imagine that should work, Sorry thinking outside with a solution that may work before a response can hit >.>

Edited by tweakster2010

Share this post


Link to post
Share on other sites
water

You can only access Outlook when it has been started with the same privileges as the script you start.
This means that if you start Outlook as a normal user and then run a script that requires admin privileges you can't access the running Outlook instance. But it should be possible (though I have never tested) to run and access Outlook as admin.

You could split your code in two parts: Start with primary account privileges, then call the second script which requires admin rights (use RunWait) and when finished you send the mails from the first script.


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
tweakster2010

I through the code you recommended into the program i made. It requires Admin for full functions and adds a login feature to hit my Admin ID and my Regular ID. I put the script you gave at the very top below the includes so it errors with just requireadmin hitting and before I truely log in. I also put it in a separate script and attached the requireadmin and it errors as well there. Now my regular ID has local admin rights but my admin ID has domain admin rights (only reason I have it set to login this way is for access of network programs requiring my admin ID to access instead). A little off topic but in line with why it didnt work for me before. I tested this with admin privileges before and didnt look at it any other way(when I still was learning stuff).

Share this post


Link to post
Share on other sites
water

I was thinking of this two scripts. Compile them and store them in the same directory. To execute run MainScript.exe

MainScript:

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

Global $aMails
RunWait(@ScriptDir & "\AdminScript.exe")
_FileReadToArray(@ScriptDir & "\Mails.txt", $aMails)
$oOl = _OL_Open()
ConsoleWrite("_OL_Open: @error = " & @error & ", @extended = " & @extended & @crlf)
; Do all the mail creating stuff from $aMails here
_OL_Close($oOL)
ConsoleWrite("_OL_Close: @error = " & @error & ", @extended = " & @extended & @crlf)


AdminScript:

#Requireadmin
; Do all the admin stuff here
; Write to @ScriptDir & "\Mails.txt" all info you need to put into the mails. I suggest one record per mail with the data separated by ,

Edit: Fixed the name of the second script.

Edited by water

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
tweakster2010

That is the route I planned on going, making my mail a separate instance so I dont have to worry about it as i would also just utilize it as a shellexecute so it never hits the permissions. :)

Share this post


Link to post
Share on other sites
tweakster2010

Ok just trying to do a test run with it with a VERY generic script.

With requireadmin it does not present an error without requireadmin is populates error code 4400.

 

When I left the email as an alias i would get a draft of undefined user (aka if i just used my name instead of the @workemail) When I add in @workemail it doesnt error just eventually ends. Never sends an e-mail either.

 

I also tested by trying to push it to another user and still nothing. Maybe I am just not understanding the UDF (checked the Wiki out and this script on the example looks as straight forward as I could get for just testing my ability to do so on the network).

#RequireAdmin
$oOL = _OL_Open()
_OL_Wrapper_SendMail($oOL, "(mywork email)", "", "", "Testmail", "This is the Body of the Email", "", $olFormatHTML, $olImportanceHigh)
If @error Then MsgBox(0,"error",@error & "   " & @extended)
_OL_Close($oOL)

 

EDIT update

 

If I remove requireadmin and put the full email address it changes to err 6002 (not having access to the encrypted file). So I think in the end This runs me into larger issues and pushes my bounds a little further than I know right now. Definitely holding to still learning quite a bit! lol.

Edited by tweakster2010

Share this post


Link to post
Share on other sites
water

4400 means that a recipient could not have been resolved.
6002 means that there is a problem with sending the item.

Another question: What is the value of @error after _OL_Open (with and without requireadmin).


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
tweakster2010

0 for no requireadmin and 1 for requireadmin

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

×