Mateus_Terra Posted May 11, 2017 Share Posted May 11, 2017 expandcollapse popupExemplo () Func Exemplo() TCPStartup() ; Inicie o serviço TCP. ; Registre OnAutoItExit para ser chamado quando o script é fechado. OnAutoItExitRegister ("OnAutoItExit") ; Atribua variáveis locais o endereço IP de loopback e a porta. Local $sIPAddress = "10.0.19.68" ; Este endereço IP só funciona para testar em seu próprio computador. Local $iPort = 80 ; Porta usada para a conexão. ; Atribua uma variável local ao soquete e conecte a um soquete de escuta com o endereço IP ea porta especificados. Local $iSocket = TCPConnect ($sIPAddress, $iPort) ; Se um erro ocorrer exibir o código de erro e retornar Falso. if @error Then ; O servidor provavelmente está offline / a porta não está aberta no servidor. Local $iError = @Error ;~ MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Não foi possível conectar-se, o código de erro:" & $iError ) Return False $SmtpServer = "smtp-mail.outlook.com" ; address for the smtp-server to use - REQUIRED $FromName = "" ; name from who the email was sent $FromAddress = "" ; address from where the mail should come $ToAddress = "" ; destination address of the email - REQUIRED $subject = "" $body = "" $AttachFiles = "" $CcAddress = "" ; address for cc - leave blank if not needed $BccAddress = "" ; address for bcc - leave blank if not needed $Importance = "High" ; Send message priority: "High", "Normal", "Low" $Username = "" ; username for the account used from where the mail gets sent - REQUIRED $Password = "" ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 25 ; port used for sending the mail $ssl = 1 ; enables/disables secure socket layer sending - put to 1 if using httpS Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl) If @error Then MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc) EndIf ; ; The UDF Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0) Local $objEmail = ObjCreate("CDO.Message") $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then $objEmail.HTMLBody = $as_Body Else $objEmail.Textbody = $as_Body & @CRLF EndIf If $s_AttachFiles <> "" Then Local $S_Files2Attach = StringSplit($s_AttachFiles, ";") For $x = 1 To $S_Files2Attach[0] $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x]) ConsoleWrite('@@ Debug(62) : $S_Files2Attach = ' & $S_Files2Attach & @LF & '>Error code: ' & @error & @LF) ;### Debug Console If FileExists($S_Files2Attach[$x]) Then $objEmail.AddAttachment ($S_Files2Attach[$x]) Else ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF) SetError(1) Return 0 EndIf Next EndIf $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 then $IPPort = 25 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf If $ssl Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True EndIf ;Update settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low" EndSwitch $objEmail.Fields.Update ; Sent the Message $objEmail.Send If @error Then SetError(2) Return $oMyRet[1] EndIf $objEmail="" EndFunc ;==>_INetSmtpMailCom Func MyErrFunc() $HexNumber = Hex($oMyError.number, 8) $oMyRet[0] = $HexNumber $oMyRet[1] = StringStripWS($oMyError.description, 3) ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF) SetError(1); something to check for when this function returns Return EndFunc ;==>MyErrFunc Else MsgBox($MB_SYSTEMMODAL, "", "Conexão bem sucedida") EndIf ; Feche o soquete. TCPCloseSocket ($iSocket) EndFunc ; ==> Exemplo Func OnAutoItExit() TCPShutdown() ; Feche o serviço TCP. EndFunc ; ==> OnAutoItExit Hello friends, someone help me! I need to do this tcp connection test and problem send an email ... But it seems like it can not have a function inside another function, I'm hooked on it! What can I do in this case? error: "Func" statement has no matching "EndFunc".: Link to comment Share on other sites More sharing options...
Developers Jos Posted May 11, 2017 Developers Share Posted May 11, 2017 Correct, so simply move them to the bottom of the script! Jos expandcollapse popupExemplo() Func Exemplo() TCPStartup() ; Inicie o serviço TCP. ; Registre OnAutoItExit para ser chamado quando o script é fechado. OnAutoItExitRegister("OnAutoItExit") ; Atribua variáveis locais o endereço IP de loopback e a porta. Local $sIPAddress = "10.0.19.68" ; Este endereço IP só funciona para testar em seu próprio computador. Local $iPort = 80 ; Porta usada para a conexão. ; Atribua uma variável local ao soquete e conecte a um soquete de escuta com o endereço IP ea porta especificados. Local $iSocket = TCPConnect($sIPAddress, $iPort) ; Se um erro ocorrer exibir o código de erro e retornar Falso. If @error Then ; O servidor provavelmente está offline / a porta não está aberta no servidor. Local $iError = @error ;~ MsgBox(BitOR($MB_SYSTEMMODAL, $MB_ICONHAND), "", "Não foi possível conectar-se, o código de erro:" & $iError ) Return False $SmtpServer = "smtp-mail.outlook.com" ; address for the smtp-server to use - REQUIRED $FromName = "" ; name from who the email was sent $FromAddress = "" ; address from where the mail should come $ToAddress = "" ; destination address of the email - REQUIRED $subject = "" $body = "" $AttachFiles = "" $CcAddress = "" ; address for cc - leave blank if not needed $BccAddress = "" ; address for bcc - leave blank if not needed $Importance = "High" ; Send message priority: "High", "Normal", "Low" $Username = "" ; username for the account used from where the mail gets sent - REQUIRED $Password = "" ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 25 ; port used for sending the mail $ssl = 1 ; enables/disables secure socket layer sending - put to 1 if using httpS Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $subject, $body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl) If @error Then MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc) EndIf ; ; The UDF Else MsgBox($MB_SYSTEMMODAL, "", "Conexão bem sucedida") EndIf ; Feche o soquete. TCPCloseSocket($iSocket) EndFunc ;==>Exemplo Func OnAutoItExit() TCPShutdown() ; Feche o serviço TCP. EndFunc ;==>OnAutoItExit Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance = "Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0) Local $objEmail = ObjCreate("CDO.Message") $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then $objEmail.HTMLBody = $as_Body Else $objEmail.Textbody = $as_Body & @CRLF EndIf If $s_AttachFiles <> "" Then Local $S_Files2Attach = StringSplit($s_AttachFiles, ";") For $x = 1 To $S_Files2Attach[0] $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x]) ConsoleWrite('@@ Debug(62) : $S_Files2Attach = ' & $S_Files2Attach & @LF & '>Error code: ' & @error & @LF) ;### Debug Console If FileExists($S_Files2Attach[$x]) Then $objEmail.AddAttachment($S_Files2Attach[$x]) Else ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF) SetError(1) Return 0 EndIf Next EndIf $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 Then $IPPort = 25 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf If $ssl Then $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True EndIf ;Update settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Low" EndSwitch $objEmail.Fields.Update ; Sent the Message $objEmail.Send If @error Then SetError(2) Return $oMyRet[1] EndIf $objEmail = "" EndFunc ;==>_INetSmtpMailCom Func MyErrFunc() $HexNumber = Hex($oMyError.number, 8) $oMyRet[0] = $HexNumber $oMyRet[1] = StringStripWS($oMyError.description, 3) ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF) SetError(1) ; something to check for when this function returns Return EndFunc ;==>MyErrFunc SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
KickStarter15 Posted May 12, 2017 Share Posted May 12, 2017 And you can simple use "Call()" to run the function. Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
Developers Jos Posted May 12, 2017 Developers Share Posted May 12, 2017 29 minutes ago, KickStarter15 said: And you can simple use "Call()" to run the function. .. Not sure how that solves the issue? .. and on top of that: one should not use Call() unless a variable is used for function parameter. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
KickStarter15 Posted May 12, 2017 Share Posted May 12, 2017 Yap, that is what I did when I've got the same issue when running function within the function. Maybe that will not solve the issue but just a tip anyway. I have it like this: Func SendClick() $VAR_SmtpServer = "domain.com" $FromName = "Name" $FromAddress = "FromAddress" $ToAddress = "Address" $Subject = GUICtrlRead($SubjectLine) $Body = "Text" $AttachFiles = "Address1" $CcAddress = "Address2" $Importance = "High" $IPPort = 25 $ssl = 0 Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $rc = _INetSmtpMailCom($VAR_SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl) If @error Then MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc) EndIf Call("_INetSmtpMailCom") EndFunc Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0) ; something here EndFunc Great script you made on this Jos, thanks it helps me a lot. Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare. Link to comment Share on other sites More sharing options...
Developers Jos Posted May 12, 2017 Developers Share Posted May 12, 2017 I am still lost what that Call() does in your posted example? You first run the Func _INetSmtpMailCom() as I would do and then later do a Call() ...why? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Mateus_Terra Posted May 12, 2017 Author Share Posted May 12, 2017 Good morning friends, Thank you, you guys are the best! I had an idea / doubt. Is there any way today to send a message via whatsapp? Like this my application ... instead of sending by email send a message via whatsapp? Link to comment Share on other sites More sharing options...
Mateus_Terra Posted May 12, 2017 Author Share Posted May 12, 2017 And another question ... I need this email alert application to run another application on a different server ... Just run another script .. any suggestions? Link to comment Share on other sites More sharing options...
Developers Jos Posted May 12, 2017 Developers Share Posted May 12, 2017 You could simply use the PSEXEC from Microsoft to make your life easy. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Mateus_Terra Posted May 12, 2017 Author Share Posted May 12, 2017 Very good ... that's what I needed ... and as for whatsapp any ideas? Link to comment Share on other sites More sharing options...
Developers Jos Posted May 12, 2017 Developers Share Posted May 12, 2017 Whatsapp is pretty closed, but you could easily use the Telegram Bot functionality. I've see a UDF for it in the Examples forum. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Mateus_Terra Posted May 12, 2017 Author Share Posted May 12, 2017 What a squeeze I'm going through, for something so simple .. But I can not get the autoit to execute psexec in any way .... What am I doing wrong? In a .bat I get calm. Run ("psexec -i -s -d \\10.0.19.68 -u machinename\administrator -p password calc") How to test open the calculator! Link to comment Share on other sites More sharing options...
Developers Jos Posted May 12, 2017 Developers Share Posted May 12, 2017 Try: Run(@comspec & " /c psexec -i -s -d \\10.0.19.68 -u machinename\administrator -p password calc") Use /k in stead of /c when only the cmd prompt flashes and nothing else. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Mateus_Terra Posted May 12, 2017 Author Share Posted May 12, 2017 'Psexec' is not recognized as an internal command Or external, an operable program or a batch file. Link to comment Share on other sites More sharing options...
Developers Jos Posted May 12, 2017 Developers Share Posted May 12, 2017 Is the workdir the correct one in the cmd prompt? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Mateus_Terra Posted May 12, 2017 Author Share Posted May 12, 2017 Not in .bat it runs on system32, already on that wheel in the script directory Link to comment Share on other sites More sharing options...
Developers Jos Posted May 12, 2017 Developers Share Posted May 12, 2017 No idea what you mean with the last post. One other thing to try is to change it to psexec.exe. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Mateus_Terra Posted May 12, 2017 Author Share Posted May 12, 2017 Link to comment Share on other sites More sharing options...
Developers Jos Posted May 12, 2017 Developers Share Posted May 12, 2017 yes .. so : is psexec located in that directory? Have you tried using psexec.exe? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Mateus_Terra Posted May 12, 2017 Author Share Posted May 12, 2017 like this?? .... Run (@comspec & "/ k psexec.exe -i -s -d \\ 10.0.19.68 Psexec is on system32 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