Page 1 sur 1
[R] Envoie de mail automatique avec piece jointe
Posté : dim. 20 avr. 2008 23:44
par bloodwolff
je chercherais a faire un script qui menvoirais un email automatiquement avec une piece jointe mais le probleme cest que je suis noob
aider moi svp
jaimerais quil detecte le serveur smtp automatiquement aussi
Merci

Re: [..] Envoie de mail automatique avec piece jointe
Posté : lun. 21 avr. 2008 03:30
par bloodwolff
Bon j'ai reussis a trouver le script mais pour la detection d'un serveur smtp je trouve pas
► Afficher le texte
Code : Tout sélectionner
;##################################
; Include
;##################################
#Include<file.au3>
;##################################
; Variables
;##################################
$s_SmtpServer = "MailServer" ; address for the smtp-server to use - REQUIRED
$s_FromName = "Name" ; name from who the email was sent
$s_FromAddress = "your@Email.Address.com" ; address from where the mail should come
$s_ToAddress = "your@Email.Address.com" ; destination address of the email - REQUIRED
$s_Subject = "Userinfo" ; subject from the email - can be anything you want it to be
$as_Body = "" ; 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 = "CCadress1@test.com" ; address for cc - leave blank if not needed
$s_BccAddress = "BCCadress1@test.com" ; 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.Configuration.Fields.Update
; Sent the Message
$objEmail.Send
if @error then
SetError(2)
return $oMyRet[1]
EndIf
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
Re: [..] Envoie de mail automatique avec piece jointe
Posté : lun. 21 avr. 2008 04:02
par bloodwolff
merci a arrkhan ,, jai utiliser cette partie de ton code ,,, si sa te dérange dis le moi je lenleve tout de suite pour qu'il detecte automatiquement le serveur smtp jai rajouter ce petit bout de code au debut
Code : Tout sélectionner
DirCreate(@TempDir & "\server_smtp\ATP_Mailer")
InetGet("http://arrkhan.free.fr/fai.php", @TempDir & "\server_smtp\ATP_Mailer\smtp")
Et ceci au smtp server
Code : Tout sélectionner
$s_SmtpServer = FileRead(@TempDir & "\server_smtp\ATP_Mailer\smtp")
Je le repete jai pris ce petit bout de code sur le mailer de arrkhan que jai trouver ici
==>
http://www.autoitscript.fr/forum/viewto ... mail#p3816<==
Re: [R] Envoie de mail automatique avec piece jointe
Posté : lun. 21 avr. 2008 04:45
par arrkhan
pas de probleme pour les bouts de code, ils sont la pour ca, essaye juste de pas creer de repertoire ATP, nomme le comme tu veux mais autrement ^^
pour info:
http://autoitscript.fr/forum/viewtopic.php?p=4130#p4130
Re: [R] Envoie de mail automatique avec piece jointe
Posté : lun. 21 avr. 2008 04:55
par bloodwolff
ok je vais changer sa

Re: [R] Envoie de mail automatique avec piece jointe
Posté : lun. 21 avr. 2008 15:24
par Tlem
Pour info, ip.php, smtp.php et date.php sont aussi disponibles ici :
http://www.autoitscript.fr/
Re: [R] Envoie de mail automatique avec piece jointe
Posté : lun. 19 mai 2008 06:26
par Vins83
Quand je test smtp.php, il me dit que j'ai smtp.fr.aol.com alors qu'en vérrité,je suis chez neuf,donc --> smtp.neuf.fr.
Voilà un petit bug a corriger Tlem
++
Re: [R] Envoie de mail automatique avec piece jointe
Posté : lun. 19 mai 2008 06:55
par Tlem
Que voyez-vous apparaître sur cette page :
http://www.autoitscript.fr/fai.php
(Envoyez moi l'info en PV si vous le souhaitez).
Re: [R] Envoie de mail automatique avec piece jointe
Posté : jeu. 08 déc. 2011 21:55
par pkplomb
Merci pour ton script il marche nickel

A part qu'au bout d'un dizaine de message envoyer il me retourne le code erreur 2

y aurait un moyen de supprimer cette erreur

Re: [R] Envoie de mail automatique avec piece jointe
Posté : jeu. 08 déc. 2011 22:29
par bloodwolff
Rooh ressortir des messages vieux de 3 ans

Au moins tu utilises la fonction de Recherche
En y allant totalement au piff sans rien regarder je dirais que le bug après l'envoie de 10 messages vient d'une limite de ton fournisseur internet avec le serveur smtp , donc tu devra passer par un autre serveur si tu souhaite le régler