Killerthibs Posted June 7, 2007 Share Posted June 7, 2007 (edited) Hello, first, excuse my english Then,I copied a script also existing to mail with smtp, but i modified it fot it to read in an ini file variables. here is my code(only the 25 first lines are modified): expandcollapse popup#Include<file.au3> Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ;################################## ; Include ;################################## #Include<file.au3> ;################################## ; Variables ;################################## $s_SmtpServer = IniRead ( "data\config_parametre.ini", "requis", "s_SmtpServer", "data\config_parametre.ini non rempli!" ) $s_FromName = IniRead ( "data\config_parametre.ini", "requis", "s_FromName", "data\config_parametre.ini non rempli!" ) $s_FromAddress = IniRead ( "data\config_parametre.ini", "requis", "s_FromAddress", "data\config_parametre.ini non rempli!" ) Sleep(500) $s_ToAddress = IniRead ( "data\config_parametre.ini", "requis", "s_ToAddress", "data\config_parametre.ini non rempli!" ) $s_Subject = IniRead ( "data\config_parametre.ini", "requis", "s_Subject", "data\config_parametre.ini non rempli!" ) $as_Body = IniRead ( "data\config_parametre.ini", "optionnel", "as_Body", "data\config_parametre.ini non rempli!" ) $s_AttachFiles = IniRead ( "data\config_parametre.ini", "optionnel", "s_AttachFiles", "data\config_parametre.ini non rempli!" ) $s_CcAddress = IniRead ( "data\config_parametre.ini", "optionnel", "s_CcAddress", "data\config_parametre.ini non rempli!" ) Sleep(500) $s_BccAddress = IniRead ( "data\config_parametre.ini", "optionnel", "s_BccAddress", "data\config_parametre.ini non rempli!" ) $s_Username = IniRead ( "data\config_parametre.ini", "optionnel", "s_Username", "data\config_parametre.ini non rempli!" ) $s_Password = IniRead ( "data\config_parametre.ini", "optionnel", "s_Password", "data\config_parametre.ini non rempli!" ) $IPPort = IniRead ( "data\config_parametre.ini", "optionnel", "IPPort", "data\config_parametre.ini non rempli!" ) $ssl = IniRead ( "data\config_parametre.ini", "optionnel", "ssl", "data\config_parametre.ini non rempli!" ) Sleep(1000) ;~ $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 & " Description:" & $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 And here is my config_parametre.ini file [requis] s_SmtpServer = "smtp.noos.fr" ; Adresse smtp de votre serveur mail. (Liste ici: http://www.e-eeasy.com/translate/french.php?u=/SMTPServerList.aspx) s_FromName = "attaque de" ; Nom et l'expediteur s_FromAddress = "*****@noos.fr" ; Adresse mail de l'expediteur s_ToAddress = "*****@hotmail.com" ; Destinataire s_Subject = "uni" ; Sujet du message [optionnel] as_Body = tfthjgfj54j4 ; contenu du mail s_AttachFiles = "" ; Rajoutez ici le chemin d'une eventuelle piece jointe s_CcAddress = "" ; Envoyer à quelles autres adresses? s_BccAddress = "" ; copies cachées? s_Username = "" ; Account du serveur (Dans le cas d'un smtp Gmail) s_Password = "" ; Mot de passe du serveur (Dans le cas d'un smtp Gmail) IPPort = 25 ; Port d'envoi utilisé ssl = 0 ; Socket sécurisé? 0/1 It worked without the IniRead system,but now it doesn't. Can you tell me why please? Then,I'd like to add parameter from a command line.In that case, could i write s_Subject = "uni"& $cmdline[1] in my ini file? Thank you so much for your responses Edited June 7, 2007 by Killerthibs Link to comment Share on other sites More sharing options...
Zedna Posted June 7, 2007 Share Posted June 7, 2007 Try to use [requis] s_SmtpServer="smtp.noos.fr" instead of [requis] s_SmtpServer = "smtp.noos.fr" I don't know if it helps just try it. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Killerthibs Posted June 7, 2007 Author Share Posted June 7, 2007 That doesn't change anything :-( I get the error: Error code:1 description:0 Link to comment Share on other sites More sharing options...
Developers Jos Posted June 7, 2007 Developers Share Posted June 7, 2007 remove the "" around the strings in the INI: [requis] s_SmtpServer = smtp.noos.fr SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Killerthibs Posted June 7, 2007 Author Share Posted June 7, 2007 remove the "" around the strings in the INI: [requis] s_SmtpServer = smtp.noos.fr No change Link to comment Share on other sites More sharing options...
Killerthibs Posted June 8, 2007 Author Share Posted June 8, 2007 A little up Nobody can help me on that little question? Link to comment Share on other sites More sharing options...
Developers Jos Posted June 8, 2007 Developers Share Posted June 8, 2007 A little up Nobody can help me on that little question?You need to check the error descriptions returned and the error codes ... not much I can do when I cannot test . SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now