Code : Tout sélectionner
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <file.au3>
#include <INet.au3>
Global $Error= ObjEvent("AutoIt.Error", "MyErrFunc")
$s_SmtpServer = _INetGetSource("http://www.autoitscript.fr/smtp.php")
$Form = GUICreate("Mailer By MaxRioux100", 683, 253, 192, 124)
$Label1 = GUICtrlCreateLabel("Adresse de l'envoyant", 80, 8, 121, 20)
GUICtrlSetFont(-1, 8, 800, 0, "Comic Sans MS")
$Mail = GUICtrlCreateCombo("", 8, 32, 249, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Label2 = GUICtrlCreateLabel("Nom de l'envoyant", 88, 56, 104, 20)
GUICtrlSetFont(-1, 8, 800, 0, "Comic Sans MS")
$Nom = GUICtrlCreateCombo("", 8, 80, 249, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Label3 = GUICtrlCreateLabel("Destinataire", 104, 104, 68, 20)
GUICtrlSetFont(-1, 8, 800, 0, "Comic Sans MS")
$Destinataire = GUICtrlCreateCombo("", 8, 128, 249, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Label4 = GUICtrlCreateLabel("Objet", 120, 152, 35, 20)
GUICtrlSetFont(-1, 8, 800, 0, "Comic Sans MS")
$Objet = GUICtrlCreateCombo("", 8, 176, 249, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
$Joint = GUICtrlCreateInput("", 8, 224, 217, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_READONLY))
$Label5 = GUICtrlCreateLabel("Fichier Joint", 104, 200, 72, 20)
GUICtrlSetFont(-1, 8, 800, 0, "Comic Sans MS")
$Fichier_joint = GUICtrlCreateButton("...", 232, 224, 27, 21)
$Label6 = GUICtrlCreateLabel("Message", 448, 8, 49, 20)
GUICtrlSetFont(-1, 8, 800, 0, "Comic Sans MS")
$Message = GUICtrlCreateEdit("", 272, 32, 401, 169)
$Label7 = GUICtrlCreateLabel("Nombre de message :", 272, 224, 107, 17)
$Nombre = GUICtrlCreateInput("1", 384, 224, 25, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
$Envoyer = GUICtrlCreateButton("Envoyer", 424, 224, 251, 21)
GUISetState(@SW_SHOW)
If FileExists("Mailer_config.ini") Then
$combo = IniReadSection("Mailer_config.ini", "Combo")
If Not @error Then
For $i = 1 to $combo[0][0]
GUICtrlSetData(Eval($combo[$i][0]),$combo[$i][1])
Next
EndIf
GUICtrlSetData($Joint,IniRead("Mailer_config.ini","Input","Joint",""))
GUICtrlSetData($Message,StringReplace(IniRead("Mailer_config.ini","Input","Message",""), _
"@CRLF",@CRLF))
EndIf
Dim $combo[4] = ["Mail", "Nom", "Destinataire", "Objet"]
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $Envoyer
IniWrite("Mailer_config.ini","Input","Joint",GUICtrlRead($Joint))
IniWrite("Mailer_config.ini","Input","Message", _
StringReplace(GUICtrlRead($Message),@CRLF,"@CRLF"))
For $i=0 to 3
If not StringInStr("|" & IniRead("Mailer_config.ini","Combo", $combo[$i],"") & "|", _
GUICtrlRead(Eval($combo[$i]))) and GUICtrlRead(Eval($combo[$i])) <> "" Then _
IniWrite("Mailer_config.ini","Combo", $combo[$i], _
IniRead("Mailer_config.ini","Combo", $combo[$i],"") & "|" & _
GUICtrlRead(Eval($combo[$i])))
Next
$fail = False
ProgressOn("","Envois en cours", "Message 0/" & GUICtrlRead($Nombre),-1,-1,1)
For $i=1 to GUICtrlRead($Nombre)
ProgressSet($i/GUICtrlRead($Nombre)*100, "Message " & $i & "/" & GUICtrlRead($Nombre))
_INetSmtpMailCom($s_SmtpServer, _
GUICtrlRead($Nom), _
GUICtrlRead($Mail), _
GUICtrlRead($Destinataire), _
GUICtrlRead($Objet), _
GUICtrlRead($Message), _
GUICtrlRead($Joint))
If @error Then
$fail = True
ExitLoop
EndIf
Next
ProgressOff()
If $fail Then
MsgBox(16,"Erreur","Impossible d'envoyer le message numero : " & $i)
Else
MsgBox(0,"Terminé!","Message envoyé avec succès")
EndIf
Case $Fichier_joint
GUICtrlSetData($Joint,FileOpenDialog("Sélectionner le fichier à joindre", @ScriptDir, "Fichier(*.*)", 5))
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
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.Configuration.Fields.Update
; Sent the Message
$objEmail.Send
if @error then
SetError(2)
return
EndIf
EndFunc ;==>_INetSmtpMailCom
Func MyErrFunc()
Return
EndFunc