Bonjour à tous,
Je débute complètement sur AutoIt mais je pense que ce peut-être LA solution à mes problèmes...
Voila l'idée. J'aimerais crée un formulaire (je ne vais pas rentrer dans les détails de ce formulaire mais il faudrait le nom, prénom, lieu, date, etc...voila mais peu importe les champs du formulaire, je me débrouillerai) et à la fin de ce formulaire, j'aimerai un seul bouton qui s'appelle "envoyer". Quand on appuie sur ce bouton, il faudrait que les informations indiquées dans le formulaire soient envoyées dans un mail automatique à cette adresse mail : julienlaf2@gmail.com. Par exemple que la personne reçoive : "Bonjour, un formulaire a été rempli avec les informations suivantes : -nom : blabla
-prenom : blabla
Est ce possible ? Merci de votre aide !
Formulaire
Règles du forum
- Merci de consulter la section "Règles du forum" et plus particulièrement "Règles et Mentions Légales du site autoitscript.fr" avant d'écrire un message.
- walkson
- Modérateur
- Messages : 1036
- Enregistré le : ven. 12 août 2011 19:49
- Localisation : Hurepoix
- Status : Hors ligne
Re: Formulaire
Bonjour,
Voici un exemple de code pour Gmail
J'ai formaté le Body avec du code html pour vous donner un aperçu
Il faudra modifier la sécurité de Gmail sinon ça ne passe pas. Voir https://www.hostinger.fr/tutoriels/util ... mtp-gmail/ étape 1
Ce code a été testé avec succès donc si vous avez des problèmes, contrôlez vos identifiants et MP
Il est possible d'avoir des problèmes avec les accents du genre
Si c'est le cas, vous pouvez régler le problème avec la fonction de Tlem
et de passer le texte à la moulinette
Voici un exemple de code pour Gmail
#include <File.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
; ===============================================================================================================================
; Variables for the _INetSmtpMailCom
; ===============================================================================================================================
Global Enum _
$g__INetSmtpMailCom_ERROR_FileNotFound = 1, _
$g__INetSmtpMailCom_ERROR_Send, _
$g__INetSmtpMailCom_ERROR_ObjectCreation, _
$g__INetSmtpMailCom_ERROR_COUNTER
Global Const $g__cdoSendUsingPickup = 1 ; Send message using the local SMTP service pickup directory.
Global Const $g__cdoSendUsingPort = 2 ; Send the message using the network (SMTP over the network). Must use this to use Delivery Notification
Global Const $g__cdoAnonymous = 0 ; Do not authenticate
Global Const $g__cdoBasic = 1 ; basic (clear-text) authentication
Global Const $g__cdoNTLM = 2 ; NTLM
Global $gs_thoussep = "."
Global $gs_decsep = ","
Global $sFileOpenDialog = ""
; Delivery Status Notifications
Global Const $g__cdoDSNDefault = 0 ; None
Global Const $g__cdoDSNNever = 1 ; None
Global Const $g__cdoDSNFailure = 2 ; Failure
Global Const $g__cdoDSNSuccess = 4 ; Success
Global Const $g__cdoDSNDelay = 8 ; Delay
;=======================================================================================================================================================
#Region ### START Koda GUI section ### Form=C:\Program Files\AutoIt3\SciTE\Koda\Templates\Form1.kxf
Global $Form1 = GUICreate("Formulaire", 273, 296, 691, 192)
GUISetBkColor(0xB9D1EA)
Global $Label1 = GUICtrlCreateLabel("Nom", 32, 8, 76, 24, $SS_RIGHT)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Input1 = GUICtrlCreateInput("", 120, 8, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Label2 = GUICtrlCreateLabel("Prénom", 32, 40, 76, 24, $SS_RIGHT)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Input2 = GUICtrlCreateInput("", 120, 40, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Label3 = GUICtrlCreateLabel("Adresse", 32, 72, 76, 24, $SS_RIGHT)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Input3 = GUICtrlCreateInput("", 120, 72, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Label4 = GUICtrlCreateLabel("Ville", 32, 104, 76, 24, $SS_RIGHT)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Input4 = GUICtrlCreateInput("", 120, 104, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Label5 = GUICtrlCreateLabel("Code postale", 24, 136, 84, 24, $SS_RIGHT)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Input5 = GUICtrlCreateInput("", 120, 136, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Label6 = GUICtrlCreateLabel("Date", 24, 168, 84, 24, $SS_RIGHT)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Input6 = GUICtrlCreateInput(_NowDate(), 120, 168, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Button1 = GUICtrlCreateButton("Envoie", 64, 208, 145, 65)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$nom = GUICtrlRead($Input1)
$prenom = GUICtrlRead($Input2)
$adresse= GUICtrlRead($Input3)
$ville = GUICtrlRead($Input4)
$code = GUICtrlRead($Input5)
$date = GUICtrlRead($Input6)
$text = '<font size="+1"><span style="color: rgb(51, 102, 255);">Bonjour, le formulaire vient d être complété' &'<BR>'& $nom & ' ' & $prenom &'<BR>'& $adresse &'<BR>'& $code & ' ' & $ville &'<BR>'& 'Le ' & $date & '</span></font>'
_Sendmail($text)
EndSwitch
WEnd
;=======================================================================================================================================================
Func _Sendmail($text)
Local $sSmtpServer = "smtp.googlemail.com" ; address for the smtp-server to use - REQUIRED
Local $sFromName = "trucmuch@gmail.com" ; name from who the email was sent
Local $sFromAddress = "trucmuch@gmail.com" ; address from where the mail should come
Local $sToAddress = "jerecois@gmail.com" ; destination address of the email - REQUIRED
Local $sSubject = "FORMULAIRE" ; subject from the email - can be anything you want it to be
Local $sBody = $text ; the messagebody from the mail - can be left blank but then you get a blank mail
Local $sAttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
Local $sCcAddress = "" ; address for cc - leave blank if not needed
Local $sBccAddress = "" ; address for bcc - leave blank if not needed
Local $sImportance = "Normal" ; Send message priority: "High", "Normal", "Low"
Local $sUsername = "trucmuch@gmail.com" ; username for the account used from where the mail gets sent - REQUIRED
Local $sPassword = "********" ; password for the account used from where the mail gets sent - REQUIRED
Local $iIPPort = 465 ; GMAIL port used for sending the mail
Local $bSSL = True ; GMAIL enables/disables secure socket layer sending - set to True if using httpS
Local $bIsHTMLBody = False
Local $iDSNOptions = $g__cdoDSNDefault
Local $rc = _INetSmtpMailCom($sSmtpServer, $sFromName, $sFromAddress, $sToAddress, $sSubject, $sBody, $sAttachFiles, $sCcAddress, $sBccAddress, $sImportance, $sUsername, $sPassword, $iIPPort, $bSSL, $bIsHTMLBody, $iDSNOptions)
If @error Then
MsgBox(0, "_INetSmtpMailCom(): Error sending message", _
"Error code: " & @error & @CRLF & @CRLF & _
"Error Hex Number: " & _INetSmtpMailCom_ErrHexNumber() & @CRLF & @CRLF & _
"Description: " & _INetSmtpMailCom_ErrDescription() & @CRLF & @CRLF & _
"Description (rc): " & $rc & @CRLF & @CRLF & _
"ScriptLine: " & _INetSmtpMailCom_ErrScriptLine() _
)
ConsoleWrite("### COM Error ! Number: " & _INetSmtpMailCom_ErrHexNumber() & " ScriptLine: " & _INetSmtpMailCom_ErrScriptLine() & " Description:" & _INetSmtpMailCom_ErrDescription() & @LF)
Else
Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(262208, "SUCCESS", ":-)", 5)
EndIf
EndFunc ;==>_Enviarmail
#Region UDF Functions
; The UDF
; #FUNCTION# ====================================================================================================================
; Name ..........: _INetSmtpMailCom
; Description ...:
; Syntax ........: _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[, $bSSL = False[, $bIsHTMLBody = False[, $iDSNOptions = $g__cdoDSNDefault]]]]]]]]]]]])
; Parameters ....: $s_SmtpServer - A string value.
; $s_FromName - A string value.
; $s_FromAddress - A string value.
; $s_ToAddress - A string value.
; $s_Subject - [optional] A string value. Default is "".
; $s_Body - [optional] A string value. Default is "".
; $s_AttachFiles - [optional] A string value. Default is "".
; $s_CcAddress - [optional] A string value. Default is "".
; $s_BccAddress - [optional] A string value. Default is "".
; $s_Importance - [optional] A string value. Default is "Normal".
; $s_Username - [optional] A string value. Default is "".
; $s_Password - [optional] A string value. Default is "".
; $IPPort - [optional] An integer value. Default is 25.
; $bSSL - [optional] A binary value. Default is False.
; $bIsHTMLBody - [optional] A binary value. Default is False.
; $iDSNOptions - [optional] An integer value. Default is $g__cdoDSNDefault.
; Return values .: None
; Author ........: Jos
; Modified ......: mLipok
; Remarks .......:
; Related .......: http://www.autoitscript.com/forum/topic/23860-smtp-mailer-that-supports-html-and-attachments/
; Link ..........: http://www.autoitscript.com/forum/topic/167292-smtp-mailer-udf/
; Example .......: Yes
; ===============================================================================================================================
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $s_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance = "Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $bSSL = False, $bIsHTMLBody = False, $iDSNOptions = $g__cdoDSNDefault)
; init Error Handler
_INetSmtpMailCom_ErrObjInit()
Local $objEmail = ObjCreate("CDO.Message")
If Not IsObj($objEmail) Then Return SetError($g__INetSmtpMailCom_ERROR_ObjectCreation, Dec(_INetSmtpMailCom_ErrHexNumber()), _INetSmtpMailCom_ErrDescription())
; Clear previous Err information
_INetSmtpMailCom_ErrHexNumber(0)
_INetSmtpMailCom_ErrDescription('')
_INetSmtpMailCom_ErrScriptLine('')
$objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
$objEmail.To = $s_ToAddress
If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
$objEmail.Subject = $s_Subject
; Select whether or not the content is sent as plain text or HTM
If $bIsHTMLBody Then
$objEmail.Textbody = $s_Body & @CRLF
Else
$objEmail.HTMLBody = $s_Body
EndIf
; Add Attachments
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
ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
$objEmail.AddAttachment($S_Files2Attach[$x])
Else
ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
Return SetError($g__INetSmtpMailCom_ERROR_FileNotFound, 0, 0)
EndIf
Next
EndIf
; Set Email Configuration
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = $g__cdoSendUsingPort
$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") = $g__cdoBasic
$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
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = $bSSL
;Update Configuration 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
; Set DSN options
If $iDSNOptions <> $g__cdoDSNDefault And $iDSNOptions <> $g__cdoDSNNever Then
$objEmail.DSNOptions = $iDSNOptions
$objEmail.Fields.Item("urn:schemas:mailheader:disposition-notification-to") = $s_FromAddress
;~ $objEmail.Fields.Item("urn:schemas:mailheader:return-receipt-to") = $s_FromAddress
EndIf
; Update Importance and Options fields
$objEmail.Fields.Update
; Sent the Message
$objEmail.Send
If @error Then
_INetSmtpMailCom_ErrObjCleanUp()
Return SetError($g__INetSmtpMailCom_ERROR_Send, Dec(_INetSmtpMailCom_ErrHexNumber()), _INetSmtpMailCom_ErrDescription())
EndIf
; CleanUp
$objEmail = ""
_INetSmtpMailCom_ErrObjCleanUp()
EndFunc ;==>_INetSmtpMailCom
;
; Com Error Handler
Func _INetSmtpMailCom_ErrObjInit($bParam = Default)
Local Static $oINetSmtpMailCom_Error = Default
If $bParam == 'CleanUp' And $oINetSmtpMailCom_Error <> Default Then
$oINetSmtpMailCom_Error = ''
Return $oINetSmtpMailCom_Error
EndIf
If $oINetSmtpMailCom_Error = Default Then
$oINetSmtpMailCom_Error = ObjEvent("AutoIt.Error", "_INetSmtpMailCom_ErrFunc")
EndIf
Return $oINetSmtpMailCom_Error
EndFunc ;==>_INetSmtpMailCom_ErrObjInit
Func _INetSmtpMailCom_ErrObjCleanUp()
_INetSmtpMailCom_ErrObjInit('CleanUp')
EndFunc ;==>_INetSmtpMailCom_ErrObjCleanUp
Func _INetSmtpMailCom_ErrHexNumber($vData = Default)
Local Static $vReturn = 0
If $vData <> Default Then $vReturn = $vData
Return $vReturn
EndFunc ;==>_INetSmtpMailCom_ErrHexNumber
Func _INetSmtpMailCom_ErrDescription($sData = Default)
Local Static $sReturn = ''
If $sData <> Default Then $sReturn = $sData
Return $sReturn
EndFunc ;==>_INetSmtpMailCom_ErrDescription
Func _INetSmtpMailCom_ErrScriptLine($iData = Default)
Local Static $iReturn = ''
If $iData <> Default Then $iReturn = $iData
Return $iReturn
EndFunc ;==>_INetSmtpMailCom_ErrScriptLine
Func _INetSmtpMailCom_ErrFunc()
_INetSmtpMailCom_ErrObjInit()
_INetSmtpMailCom_ErrHexNumber(Hex(_INetSmtpMailCom_ErrObjInit().number, 8))
_INetSmtpMailCom_ErrDescription(StringStripWS(_INetSmtpMailCom_ErrObjInit().description, 3))
_INetSmtpMailCom_ErrScriptLine(_INetSmtpMailCom_ErrObjInit().ScriptLine)
SetError(1) ; something to check for when this function returns
Return
EndFunc ;==>_INetSmtpMailCom_ErrFunc
#EndRegion UDF Functions
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
; ===============================================================================================================================
; Variables for the _INetSmtpMailCom
; ===============================================================================================================================
Global Enum _
$g__INetSmtpMailCom_ERROR_FileNotFound = 1, _
$g__INetSmtpMailCom_ERROR_Send, _
$g__INetSmtpMailCom_ERROR_ObjectCreation, _
$g__INetSmtpMailCom_ERROR_COUNTER
Global Const $g__cdoSendUsingPickup = 1 ; Send message using the local SMTP service pickup directory.
Global Const $g__cdoSendUsingPort = 2 ; Send the message using the network (SMTP over the network). Must use this to use Delivery Notification
Global Const $g__cdoAnonymous = 0 ; Do not authenticate
Global Const $g__cdoBasic = 1 ; basic (clear-text) authentication
Global Const $g__cdoNTLM = 2 ; NTLM
Global $gs_thoussep = "."
Global $gs_decsep = ","
Global $sFileOpenDialog = ""
; Delivery Status Notifications
Global Const $g__cdoDSNDefault = 0 ; None
Global Const $g__cdoDSNNever = 1 ; None
Global Const $g__cdoDSNFailure = 2 ; Failure
Global Const $g__cdoDSNSuccess = 4 ; Success
Global Const $g__cdoDSNDelay = 8 ; Delay
;=======================================================================================================================================================
#Region ### START Koda GUI section ### Form=C:\Program Files\AutoIt3\SciTE\Koda\Templates\Form1.kxf
Global $Form1 = GUICreate("Formulaire", 273, 296, 691, 192)
GUISetBkColor(0xB9D1EA)
Global $Label1 = GUICtrlCreateLabel("Nom", 32, 8, 76, 24, $SS_RIGHT)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Input1 = GUICtrlCreateInput("", 120, 8, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Label2 = GUICtrlCreateLabel("Prénom", 32, 40, 76, 24, $SS_RIGHT)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Input2 = GUICtrlCreateInput("", 120, 40, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Label3 = GUICtrlCreateLabel("Adresse", 32, 72, 76, 24, $SS_RIGHT)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Input3 = GUICtrlCreateInput("", 120, 72, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Label4 = GUICtrlCreateLabel("Ville", 32, 104, 76, 24, $SS_RIGHT)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Input4 = GUICtrlCreateInput("", 120, 104, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Label5 = GUICtrlCreateLabel("Code postale", 24, 136, 84, 24, $SS_RIGHT)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Input5 = GUICtrlCreateInput("", 120, 136, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Label6 = GUICtrlCreateLabel("Date", 24, 168, 84, 24, $SS_RIGHT)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Input6 = GUICtrlCreateInput(_NowDate(), 120, 168, 121, 24)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Button1 = GUICtrlCreateButton("Envoie", 64, 208, 145, 65)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$nom = GUICtrlRead($Input1)
$prenom = GUICtrlRead($Input2)
$adresse= GUICtrlRead($Input3)
$ville = GUICtrlRead($Input4)
$code = GUICtrlRead($Input5)
$date = GUICtrlRead($Input6)
$text = '<font size="+1"><span style="color: rgb(51, 102, 255);">Bonjour, le formulaire vient d être complété' &'<BR>'& $nom & ' ' & $prenom &'<BR>'& $adresse &'<BR>'& $code & ' ' & $ville &'<BR>'& 'Le ' & $date & '</span></font>'
_Sendmail($text)
EndSwitch
WEnd
;=======================================================================================================================================================
Func _Sendmail($text)
Local $sSmtpServer = "smtp.googlemail.com" ; address for the smtp-server to use - REQUIRED
Local $sFromName = "trucmuch@gmail.com" ; name from who the email was sent
Local $sFromAddress = "trucmuch@gmail.com" ; address from where the mail should come
Local $sToAddress = "jerecois@gmail.com" ; destination address of the email - REQUIRED
Local $sSubject = "FORMULAIRE" ; subject from the email - can be anything you want it to be
Local $sBody = $text ; the messagebody from the mail - can be left blank but then you get a blank mail
Local $sAttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
Local $sCcAddress = "" ; address for cc - leave blank if not needed
Local $sBccAddress = "" ; address for bcc - leave blank if not needed
Local $sImportance = "Normal" ; Send message priority: "High", "Normal", "Low"
Local $sUsername = "trucmuch@gmail.com" ; username for the account used from where the mail gets sent - REQUIRED
Local $sPassword = "********" ; password for the account used from where the mail gets sent - REQUIRED
Local $iIPPort = 465 ; GMAIL port used for sending the mail
Local $bSSL = True ; GMAIL enables/disables secure socket layer sending - set to True if using httpS
Local $bIsHTMLBody = False
Local $iDSNOptions = $g__cdoDSNDefault
Local $rc = _INetSmtpMailCom($sSmtpServer, $sFromName, $sFromAddress, $sToAddress, $sSubject, $sBody, $sAttachFiles, $sCcAddress, $sBccAddress, $sImportance, $sUsername, $sPassword, $iIPPort, $bSSL, $bIsHTMLBody, $iDSNOptions)
If @error Then
MsgBox(0, "_INetSmtpMailCom(): Error sending message", _
"Error code: " & @error & @CRLF & @CRLF & _
"Error Hex Number: " & _INetSmtpMailCom_ErrHexNumber() & @CRLF & @CRLF & _
"Description: " & _INetSmtpMailCom_ErrDescription() & @CRLF & @CRLF & _
"Description (rc): " & $rc & @CRLF & @CRLF & _
"ScriptLine: " & _INetSmtpMailCom_ErrScriptLine() _
)
ConsoleWrite("### COM Error ! Number: " & _INetSmtpMailCom_ErrHexNumber() & " ScriptLine: " & _INetSmtpMailCom_ErrScriptLine() & " Description:" & _INetSmtpMailCom_ErrDescription() & @LF)
Else
Dim $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox(262208, "SUCCESS", ":-)", 5)
EndIf
EndFunc ;==>_Enviarmail
#Region UDF Functions
; The UDF
; #FUNCTION# ====================================================================================================================
; Name ..........: _INetSmtpMailCom
; Description ...:
; Syntax ........: _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[, $bSSL = False[, $bIsHTMLBody = False[, $iDSNOptions = $g__cdoDSNDefault]]]]]]]]]]]])
; Parameters ....: $s_SmtpServer - A string value.
; $s_FromName - A string value.
; $s_FromAddress - A string value.
; $s_ToAddress - A string value.
; $s_Subject - [optional] A string value. Default is "".
; $s_Body - [optional] A string value. Default is "".
; $s_AttachFiles - [optional] A string value. Default is "".
; $s_CcAddress - [optional] A string value. Default is "".
; $s_BccAddress - [optional] A string value. Default is "".
; $s_Importance - [optional] A string value. Default is "Normal".
; $s_Username - [optional] A string value. Default is "".
; $s_Password - [optional] A string value. Default is "".
; $IPPort - [optional] An integer value. Default is 25.
; $bSSL - [optional] A binary value. Default is False.
; $bIsHTMLBody - [optional] A binary value. Default is False.
; $iDSNOptions - [optional] An integer value. Default is $g__cdoDSNDefault.
; Return values .: None
; Author ........: Jos
; Modified ......: mLipok
; Remarks .......:
; Related .......: http://www.autoitscript.com/forum/topic/23860-smtp-mailer-that-supports-html-and-attachments/
; Link ..........: http://www.autoitscript.com/forum/topic/167292-smtp-mailer-udf/
; Example .......: Yes
; ===============================================================================================================================
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $s_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance = "Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $bSSL = False, $bIsHTMLBody = False, $iDSNOptions = $g__cdoDSNDefault)
; init Error Handler
_INetSmtpMailCom_ErrObjInit()
Local $objEmail = ObjCreate("CDO.Message")
If Not IsObj($objEmail) Then Return SetError($g__INetSmtpMailCom_ERROR_ObjectCreation, Dec(_INetSmtpMailCom_ErrHexNumber()), _INetSmtpMailCom_ErrDescription())
; Clear previous Err information
_INetSmtpMailCom_ErrHexNumber(0)
_INetSmtpMailCom_ErrDescription('')
_INetSmtpMailCom_ErrScriptLine('')
$objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
$objEmail.To = $s_ToAddress
If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
$objEmail.Subject = $s_Subject
; Select whether or not the content is sent as plain text or HTM
If $bIsHTMLBody Then
$objEmail.Textbody = $s_Body & @CRLF
Else
$objEmail.HTMLBody = $s_Body
EndIf
; Add Attachments
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
ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
$objEmail.AddAttachment($S_Files2Attach[$x])
Else
ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
Return SetError($g__INetSmtpMailCom_ERROR_FileNotFound, 0, 0)
EndIf
Next
EndIf
; Set Email Configuration
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = $g__cdoSendUsingPort
$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") = $g__cdoBasic
$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
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = $bSSL
;Update Configuration 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
; Set DSN options
If $iDSNOptions <> $g__cdoDSNDefault And $iDSNOptions <> $g__cdoDSNNever Then
$objEmail.DSNOptions = $iDSNOptions
$objEmail.Fields.Item("urn:schemas:mailheader:disposition-notification-to") = $s_FromAddress
;~ $objEmail.Fields.Item("urn:schemas:mailheader:return-receipt-to") = $s_FromAddress
EndIf
; Update Importance and Options fields
$objEmail.Fields.Update
; Sent the Message
$objEmail.Send
If @error Then
_INetSmtpMailCom_ErrObjCleanUp()
Return SetError($g__INetSmtpMailCom_ERROR_Send, Dec(_INetSmtpMailCom_ErrHexNumber()), _INetSmtpMailCom_ErrDescription())
EndIf
; CleanUp
$objEmail = ""
_INetSmtpMailCom_ErrObjCleanUp()
EndFunc ;==>_INetSmtpMailCom
;
; Com Error Handler
Func _INetSmtpMailCom_ErrObjInit($bParam = Default)
Local Static $oINetSmtpMailCom_Error = Default
If $bParam == 'CleanUp' And $oINetSmtpMailCom_Error <> Default Then
$oINetSmtpMailCom_Error = ''
Return $oINetSmtpMailCom_Error
EndIf
If $oINetSmtpMailCom_Error = Default Then
$oINetSmtpMailCom_Error = ObjEvent("AutoIt.Error", "_INetSmtpMailCom_ErrFunc")
EndIf
Return $oINetSmtpMailCom_Error
EndFunc ;==>_INetSmtpMailCom_ErrObjInit
Func _INetSmtpMailCom_ErrObjCleanUp()
_INetSmtpMailCom_ErrObjInit('CleanUp')
EndFunc ;==>_INetSmtpMailCom_ErrObjCleanUp
Func _INetSmtpMailCom_ErrHexNumber($vData = Default)
Local Static $vReturn = 0
If $vData <> Default Then $vReturn = $vData
Return $vReturn
EndFunc ;==>_INetSmtpMailCom_ErrHexNumber
Func _INetSmtpMailCom_ErrDescription($sData = Default)
Local Static $sReturn = ''
If $sData <> Default Then $sReturn = $sData
Return $sReturn
EndFunc ;==>_INetSmtpMailCom_ErrDescription
Func _INetSmtpMailCom_ErrScriptLine($iData = Default)
Local Static $iReturn = ''
If $iData <> Default Then $iReturn = $iData
Return $iReturn
EndFunc ;==>_INetSmtpMailCom_ErrScriptLine
Func _INetSmtpMailCom_ErrFunc()
_INetSmtpMailCom_ErrObjInit()
_INetSmtpMailCom_ErrHexNumber(Hex(_INetSmtpMailCom_ErrObjInit().number, 8))
_INetSmtpMailCom_ErrDescription(StringStripWS(_INetSmtpMailCom_ErrObjInit().description, 3))
_INetSmtpMailCom_ErrScriptLine(_INetSmtpMailCom_ErrObjInit().ScriptLine)
SetError(1) ; something to check for when this function returns
Return
EndFunc ;==>_INetSmtpMailCom_ErrFunc
#EndRegion UDF Functions
Il faudra modifier la sécurité de Gmail sinon ça ne passe pas. Voir https://www.hostinger.fr/tutoriels/util ... mtp-gmail/ étape 1
Ce code a été testé avec succès donc si vous avez des problèmes, contrôlez vos identifiants et MP
Il est possible d'avoir des problèmes avec les accents du genre
Bonjour, le formulaire vient d �tre compl�t�
Si c'est le cas, vous pouvez régler le problème avec la fonction de Tlem
Func _ConvertAnsiToUtf8($sText)
Local $tUnicode = _WinAPI_MultiByteToWideChar($sText)
If @error Then Return SetError(@error, 0, "")
Local $sUtf8 =_WinAPI_WideCharToMultiByte(DllStructGetPtr($tUnicode), 65001)
If @error Then Return SetError(@error, 0, "")
Return SetError(0, 0, $sUtf8)
EndFunc ;==>_ConvertAnsiToUtf8
Local $tUnicode = _WinAPI_MultiByteToWideChar($sText)
If @error Then Return SetError(@error, 0, "")
Local $sUtf8 =_WinAPI_WideCharToMultiByte(DllStructGetPtr($tUnicode), 65001)
If @error Then Return SetError(@error, 0, "")
Return SetError(0, 0, $sUtf8)
EndFunc ;==>_ConvertAnsiToUtf8
$text = _ConvertAnsiToUtf8($text)
sans oublier de rajouter l'include en haut du code#include <WinAPIConv.au3>
Cordialement,
Walkson
"Horas non numero nisi serenas " Le canon de midi
(Je ne compte que les heures heureuses)
Walkson
"Horas non numero nisi serenas " Le canon de midi
(Je ne compte que les heures heureuses)
Re: Formulaire
Bonjour,
Je débute sous AutoIT
Je suis en train de tester ce formulaire, merci pour le partage
Lorsque je tente de faire un envoi, j'ai de message (Via SciTe) pour la ligne 281:
==> Variable used without being declared.:
Local $iDSNOptions = $g__cdoDSNDefault
Local $iDSNOptions = ^ ERROR
>Exit code: 1 Time: 2.201
Voici la ligne 281:
Local $iDSNOptions = $g__cdoDSNDefault
Qui correspond bien au script d'origine.
Auriez-vous une idée du problème ?
Merci d'avance et bonne journée.
EDIT: Il m'en manquait un bout.... le Noob...
Il me manquait toute la partie "Variables for the _INetSmtpMailCom"
Après avoir modifié la fenêtre avec KODA, j'ai également eu un problème sur la fonction _NowDate(). Koda me rajoutait des " pour faire: ("_NowDate()") et cela ne fonctionnait plus.
Je débute sous AutoIT
Je suis en train de tester ce formulaire, merci pour le partage

Lorsque je tente de faire un envoi, j'ai de message (Via SciTe) pour la ligne 281:
==> Variable used without being declared.:
Local $iDSNOptions = $g__cdoDSNDefault
Local $iDSNOptions = ^ ERROR
>Exit code: 1 Time: 2.201
Voici la ligne 281:
Local $iDSNOptions = $g__cdoDSNDefault
Qui correspond bien au script d'origine.
Auriez-vous une idée du problème ?
Merci d'avance et bonne journée.
EDIT: Il m'en manquait un bout.... le Noob...

Après avoir modifié la fenêtre avec KODA, j'ai également eu un problème sur la fonction _NowDate(). Koda me rajoutait des " pour faire: ("_NowDate()") et cela ne fonctionnait plus.