Sign in to follow this  
Followers 0
Bertus

Grab TEXT from GUI then send info via email

5 posts in this topic

Hello everyone,

My 3rd post and starting to like AutoIT in such a way I cant leave it alone - however I have run into a little issue and was wondering if someone can help me on this one - I have read numerous posts but not sure what to look for in the following sceanrio.

This will be used for some users on there pc's to send a problem to the support department in order to resolve issues quicker.

Please bare with me on this one. :-)

I have a GUI with 4 Input fields with 2 buttons together with an email script.

Firstly, here is my code for the GUI:

##include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

TCPStartup()

$Form2 = GUICreate("Support", 301, 328, 544, 179)
$Label2 = GUICtrlCreateLabel("HostName", 32, 72, 84, 17)
$Label3 = GUICtrlCreateLabel("IP", 32, 112, 84, 17)
$Input1 = GUICtrlCreateInput("SFE Number", 128, 32, 129, 21)
$Input2 = GUICtrlCreateInput(@ComputerName, 128, 72, 129, 21)
$Input3 = GUICtrlCreateInput("", 128, 112, 129, 21)
$Label1 = GUICtrlCreateLabel("SFE", 32, 32, 84, 17)
$Button1 = GUICtrlCreateButton("Collect Info", 32, 216, 81, 33)
$Button2 = GUICtrlCreateButton("Send Info", 152, 216, 105, 33)
$Progress1 = GUICtrlCreateProgress(32, 280, 225, 17)
$Combo1 = GUICtrlCreateCombo("Select Issue", 128, 152, 129, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData($Combo1, "Avaya|C4 - Cant Login", "item3")
GUICtrlSetData($Combo1, "C4 - Cant Open|C4 - Account Search", "item4")
GUICtrlSetData($Combo1, "No Calls|Inbound", "item5")
GUICtrlSetData($Combo1, "Outbound|Headset ID in Use", "item6")
GUICtrlSetData($Combo1, "Zioper|C4", "item7")
GUICtrlSetData($Combo1, "Zioper|C4", "item8")
$Label4 = GUICtrlCreateLabel("Problem:", 32, 152, 76, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            TCPShutdown()
            Exit

            #Case $Button2
            #GUICtrlSetData($Input2, "")            GUICtrlSetData($Input3, "")
        Case $Button1
            GUICtrlSetData($Input3, TCPNameToIP(GUICtrlRead($Input2)))
    EndSwitch
WEnd

Now the above is working as I want it to work, however one can see I have hashed out the Case $Button2 aka "Send Info".

As soon as the user opens the GUI and add the SFE number and select the nature of the problem and click on Collect Info, it will grab the IP address of the computer with the hostname.

This is where my problem is, once you click on "Send Info" it needs to Grab the SFE, Hostname, IP, Problem, and send this via email to the IT group as $s_Subject as "Problem" and $as_body as SFE,Hostname,IP.

This is my mail script:

$s_SmtpServer = "0.0.0.0"
#$s_FromName = "localhost"
$s_FromName = "Bertus"
$s_FromAddress = "notification@test.com"
$s_ToAddress = "bertusn@test.com"
$s_Subject = "Nature or discription of Problem" # Nature of Problem as Subject

Dim $as_Body[2]
$as_Body[0] = "IP/Hostname/SFE" # Details in Body
$as_Body[1] = "Nature or discription of Problem" # This line not as important
$Response = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
$err = @error
If $Response = 1 Then
    MsgBox(0, "Success!", "Info sent")
Else
    MsgBox(0, "Error!", "Mail failed - Please retry or call Support" & $err)
EndIf

The mail script works if I run it on it's own.

How can I go about incorporating the "send Info" button with the mail script in order to receive the GIU selections via email? Im sure it might be something small but I am not sure.

Any Guru out there that can help me or is willing to share some knowledge on this one :-) I will be highly gratefull, and at the same time learn something new aswell.

Thank you in advance.

Share this post


Link to post
Share on other sites



Wrap the email send code in a function, then call the function in your

Case Button2 code, passing the parameters read from your inputs.

Share this post


Link to post
Share on other sites

Thanks for the reply man, appreciated, but I have no idea what you just said. :  But I will learn.

What function will it be, my short time with this I have learned there is a few and im sure there is a few that I am not aware of.

Thank you again

Share this post


Link to post
Share on other sites

A suggestion...

TCPStartup()

$Form2 = GUICreate("Support", 301, 328, 544, 179)
$Label1 = GUICtrlCreateLabel("SFE", 32, 32, 84, 17)
$Label2 = GUICtrlCreateLabel("HostName", 32, 72, 84, 17)
$Label3 = GUICtrlCreateLabel("IP", 32, 112, 84, 17)
$Input1 = GUICtrlCreateInput("SFE Number", 128, 32, 129, 21)
$Input2 = GUICtrlCreateInput(@ComputerName, 128, 72, 129, 21)
$Input3 = GUICtrlCreateInput("", 128, 112, 129, 21)
$Button1 = GUICtrlCreateButton("Collect Info", 32, 216, 81, 33)
$Button2 = GUICtrlCreateButton("Send Info", 152, 216, 105, 33)
$Progress1 = GUICtrlCreateProgress(32, 280, 225, 17)
$Combo1 = GUICtrlCreateCombo("Select Issue", 128, 152, 129, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData($Combo1, "Avaya|C4 - Cant Login", "item3")
GUICtrlSetData($Combo1, "C4 - Cant Open|C4 - Account Search", "item4")
GUICtrlSetData($Combo1, "No Calls|Inbound", "item5")
GUICtrlSetData($Combo1, "Outbound|Headset ID in Use", "item6")
GUICtrlSetData($Combo1, "Zioper|C4", "item7")
GUICtrlSetData($Combo1, "Zioper|C4", "item8")
$Label4 = GUICtrlCreateLabel("Problem:", 32, 152, 76, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            TCPShutdown()
            Exit
            
        Case $Button1
            GUICtrlSetData($Input3, TCPNameToIP(GUICtrlRead($Input2)))

        Case $Button2
            ;#GUICtrlSetData($Input2, "")            GUICtrlSetData($Input3, "")
            Local $aParameters[4] ; create array to pass info to func
            $aParameters[0] = GUICtrlRead($Input1) ; SFE Number
            $aParameters[1] = GUICtrlRead($Input2) ; HostName
            $aParameters[2] = GUICtrlRead($Input3) ; IP address
            $aParameters[3] = GUICtrlRead($Combo1) ; Issue
            SendMail($aParameters) ; call function passing array containing collected info
            
    EndSwitch
WEnd


Func SendMail($aInput)
    ; SFE Number is in $aInput[0]
    ; HostName is in $aInput[1]
    ; IP address is in $aInput[2]
    ; Issue is in $aInput[3]
    $s_SmtpServer = "0.0.0.0"
    $s_FromName = "localhost"
    $s_FromName = "Bertus"
    $s_FromAddress = "notification@test.com"
    $s_ToAddress = "bertusn@test.com"
    $s_Subject = "Nature or discription of Problem" ; Nature of Problem as Subject

    ; now you can construct your subject and body using values in $aInput
    
    Dim $as_Body[2]
    $as_Body[0] = "IP/Hostname/SFE" ; Details in Body
    $as_Body[1] = "Nature or discription of Problem" ; This line not as important
    $Response = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
    $err = @error
    If $Response = 1 Then
        MsgBox(0, "Success!", "Info sent")
    Else
        MsgBox(0, "Error!", "Mail failed - Please retry or call Support" & $err)
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

Thank you dmob - was looking around for the email function, you just made it very clear and I can do now what I need to do. If I look at the code, it is really not that hard - guess I was searching in the woring area. :idea:

Thanks again for the Good pointer, appreciated it. :)

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
Sign in to follow this  
Followers 0