Je viens tout juste de me mettre à AutoIt, je trouve ça énorme, vu que je ne connais pas trop le langage de programmation et j'arrive déjà à faire un formulaire assé sympatoche...
Comme dit ci-dessus, j'ai un problème avec mon formulaire j'aimerai envoyer un mail, mais j'ai une erreur avec mon "$objEmail.Send" tant dis qu'il marche indépendamment du script.
Si quelqu'un pouvait m'aider pour ce problème ou même optimiser mon code je lui en serai très redevable.
Voici mon script en entier:
► Afficher le texte
Code : Tout sélectionner
#include <GUIConstantsEx.au3>
#Include<file.au3>
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
Global $BAJOUTER, $BRESULT, $BSEND, $i, $height, $nom, $prenom, $inpRep, $cbAcces, $ResultRep, $ResultAcces, $lblsrv,$test
Global $inpRepN[8], $cbAccesN[8],$objEmail
Global $s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl
$i = 0
$height = 90
Main ()
Func Main()
Local $BTNEXIT, $msg, $guiread
Dim $lblnom, $lblprenom, $cbAcces1,$lstsrv, $lblAcces, $lblRep
GuiCreate("***", 400, 400,0,0)
$lblnom = GuiCtrlCreateLabel("***:", 10, 15)
$nom = GuiCtrlCreateInput("", 10, 35, 80, 20)
;GuiCtrlSetBkColor($nom, )
$lblprenom = GuiCtrlCreateLabel("***:", 100, 15)
$prenom = GuiCtrlCreateInput("", 100, 35, 80, 20)
$lblsrv = GuiCtrlCreateLabel("***", 10, 70)
$lstsrv = GuiCtrlCreateList("", 10, 90, 100, 90)
GuiCtrlSetData(-1, "***|***|***")
$lblRep = GuiCtrlCreateLabel("***", 120, 70)
$inpRep = GuiCtrlCreateInput("", 120, 90, 80, 20)
$lblAcces = GuiCtrlCreateLabel("***", 212, 70)
$cbAcces = GuiCtrlCreatecombo("Select", 212, 90, 100, 100)
GUICtrlSetData(-1, "***|***/***")
$BAJOUTER = GUICtrlCreateButton("&Ajouter", 320, 90, 70)
GUICtrlSetOnEvent($BAJOUTER, "OnAjouter")
$BTNEXIT = GUICtrlCreateButton("&Exit", 295, 370, 100)
GUICtrlSetOnEvent($BTNEXIT, "OnExit")
$BRESULT =GUICtrlCreateButton("&Result", 175, 370, 100)
GUICtrlSetOnEvent($BRESULT, "OnResult")
$BSEND =GUICtrlCreateButton("&Send", 55, 370, 100)
GUICtrlSetOnEvent($BSEND, "_INetSmtpMailCom")
GUISetOnEvent($GUI_EVENT_CLOSE, "OnClose")
GuiSetState()
while 1
Sleep(1000)
WEnd
EndFunc
OnClose()
Func OnClose()
Exit
EndFunc
OnAjouter ()
Func OnAjouter()
If $i = 7 Then
MsgBox(16,"Erreur","Vous avez atteind la limite de nombre de répertoire")
Else
$i = $i + 1
$height = $height + 30
$inpRepN[$i] = GuiCtrlCreateInput("", 120, $height, 80, 20)
$ResultRep = $inpRepN[$i]
$cbAccesN[$i] = GuiCtrlCreatecombo("Select", 212, $height, 100, 100)
GUICtrlSetData($cbAccesN[$i], "***|***/***")
$ResultAcces = $cbAccesN[$i]
EndIf
EndFunc
OnResult()
Func OnResult()
MsgBox(0,"Result",GUICtrlRead($ResultRep))
MsgBox(0,"Result",GUICtrlRead($ResultAcces))
EndFunc
OnExit()
Func OnExit()
If GUICtrlRead($nom) = "" And GUICtrlRead($prenom) = "" Then
MsgBox(16,"ERREUR","Remplis Ce p..... De NOM Et PRENOM ! ! !")
Else
If GUICtrlRead($nom) = "" Then
MsgBox(16,"ERREUR","Remplis Ce p..... De NOM ! ! !")
Else
If GUICtrlRead($prenom) = "" Then
MsgBox(16,"ERREUR","Remplis Ce p..... De PRENOM ! ! !")
Else
Exit
EndIf
EndIf
EndIf
EndFunc
$s_SmtpServer = "***" ; address for the smtp-server to use - REQUIRED
$s_FromName = "..." ; name from who the email was sent
$s_FromAddress = "" ; address from where the mail should come
$s_ToAddress = "***" ; destination address of the email - REQUIRED
$s_Subject = "sujet" ; subject from the email - can be anything you want it to be
$as_Body = "Corps du message" ; the messagebody from the mail - can be left blank but then you get a blank mail
$s_AttachFiles = "" ; the file you want to attach- leave blank if not needed
$s_CcAddress = "" ; address for cc - leave blank if not needed
$s_BccAddress = "" ; address for bcc - leave blank if not needed
$s_Username = "***" ; username for the account used from where the mail gets sent - Optional (Needed for eg GMail)
$s_Password = "***" ; password for the account used from where the mail gets sent - Optional (Needed for eg GMail)
$IPPort = 25 ; port used for sending the mail
$ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS
;~ $IPPort=465 ; GMAIL port used for sending the mail
;~ $ssl=1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS
;##################################
; Script
;##################################
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
$rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)
If @error Then
MsgBox(0, "Error sending message", "Error code:" & @error & " Rc:" & $rc)
EndIf
;
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "",$IPPort=25, $ssl=0)
$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])
If FileExists($S_Files2Attach[$x]) Then
$objEmail.AddAttachment ($S_Files2Attach[$x])
Else
$i_Error_desciption = $i_Error_desciption & @lf & 'File not found to attach: ' & $S_Files2Attach[$x]
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
$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.Fields.Update
; Sent the Message
$objEmail.Send
If @error Then
SetError(2)
Return $oMyRet[1]
EndIf
$objEmail=""
EndFunc ;==>_INetSmtpMailCom
;
;
; Com Error Handler
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


