Code : Tout sélectionner
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.2.10.0
Author: Arrkhan
Script Function: Envoi de mail de maniere autonome
#ce ----------------------------------------------------------------------------
#include<GuiConstants.au3>
#include<Inet.au3>
#NoTrayIcon
Dim $Body
Dim $as_Body[1]
$APPTitle = "ATP_Mailer"
$MailerGUI = GUICreate($APPTitle & " - Envoyer un courriel à …qui on veut ^^ by arrkhan…", 480, 300, -1, -1)
GUICtrlCreateLabel("De :", 10, 10, 40, 20)
$FromName = GUICtrlCreateInput("", 50, 7, 170, 20)
GUICtrlCreateLabel("@ :", 10, 35, 40, 20)
$FromAddress = GUICtrlCreateInput("", 50, 32, 170, 20)
GUICtrlCreateLabel("À :", 10, 55, 40, 20)
$s_ToAddress = GUICtrlCreateInput("", 50, 52, 170, 20)
GUICtrlCreateLabel("Sujet :", 10, 75, 40, 20)
$Subject = GUICtrlCreateInput("", 50, 72, 170, 20)
$Body = GUICtrlCreateEdit("", 10, 102, 460, 165)
GUICtrlSetFont($Body, 9)
$Send = GUICtrlCreateButton("Envoyer", 420, 270, 50, 20)
GUICtrlSetState($Send, $GUI_DEFBUTTON)
$answer = _VerifNetSilent()
If $answer = 1 Then
MsgBox(0, $APPTitle & " - Erreur", "Impossible de se connecter à internet, certaines fonctions ont été grisées.")
GUICtrlSetState($Send, $GUI_DISABLE)
EndIf
GUISetState()
While 1
$msg = GUIGetMsg()
If $msg = -3 Then
DirRemove(@TempDir & "\ATP\ATP_Mailer", 1)
GUIDelete($MailerGUI)
ExitLoop
EndIf
If $msg = $Send Then
$answer = _VerifNetSilent()
If $answer = 1 Then
MsgBox(0, $APPTitle & " - Erreur", "Impossible de se connecter à internet")
ExitLoop
Else
DirCreate(@TempDir & "\ATP\ATP_Mailer")
InetGet("http://arrkhan.free.fr/fai.php", @TempDir & "\ATP\ATP_Mailer\smtp")
EndIf
GUICtrlSetState($Send, $GUI_DISABLE)
$s_SmtpServer = FileRead(@TempDir & "\ATP\ATP_Mailer\smtp")
If GUICtrlRead($FromName) = "" Then
$s_FromName = "OSEF"
Else
$s_FromName = GUICtrlRead($FromName)
EndIf
If GUICtrlRead($FromAddress) = "" Then
MsgBox(0,$APPTitle, "Veuillez choisir entrer votre adresse email…",5)
Else
$s_FromAddress = GUICtrlRead($FromAddress)
EndIf
If GUICtrlRead($s_ToAddress) = "" Then
MsgBox(0,$APPTitle, "Veuillez choisir un destinataire…",5)
Else
$s_ToAddress = GUICtrlRead($s_ToAddress)
EndIf
If GUICtrlRead($Subject) = "Choisissez un sujet…" Then
MsgBox(0, $APPTitle, "Veuillez choisir un sujet svp…", 5)
GUICtrlSetState($Send, $GUI_ENABLE)
ContinueLoop
EndIf
$s_Subject = GUICtrlRead($Subject)
$as_Body[0] = GUICtrlRead($Body)
If GUICtrlRead($Body) = "" Then
MsgBox(0, $APPTitle, "Veuillez entrer un message…", 5)
GUICtrlSetState($Send, $GUI_ENABLE)
ContinueLoop
EndIf
$Response = _INetSmtpMail($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
If $Response = 1 Then
MsgBox(0, "Réussi !", "Courriel envoyé.", 2)
DirRemove(@TempDir & "\ATP\ATP_Mailer", 1)
GUIDelete($MailerGUI)
ExitLoop
Else
MsgBox(0, "Echec de l'envoi !", "Impossible d'envoyer le courriel." & @CR & "Code d'erreur : " & @error, 5)
GUICtrlSetState($Send, $GUI_ENABLE)
EndIf
Sleep(10)
EndIf
WEnd
Exit
Func _VerifNetSilent()
Ping("arrkhan.free.fr", 250)
If @error = 0 Then
Return 0 ; net ok
Else
Return 1 ; pas le net
EndIf
EndFunc ;==>_VerifNetSilent