autow Posted May 11, 2011 Posted May 11, 2011 Hi buddies,i work in a Market Company and need code script for send mail...i code using one a UDF but i got several problems... I ask for help but i wanna learn what is wrong expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ;Vars do programa Local $state[5] $Default = FileReadLine ("./unity/defcom.pif",1) ;END $state[1] = "Waiting" $state[2] = "Waiting" $state[3] = "Waiting" $state[4] = "Waiting" $state[5] = "Waiting" #Region ### START Koda GUI section ### Form=c:\documents and settings\usuário\desktop\meusfiles\pastas\koda\forms\form2_1.kxf Global $Form2_1 = GUICreate("SysSofts - Inbox", 813, 500, 336, 90) Global $Load = GUICtrlCreateButton("Load Conf", 304, 8, 75, 17) Global $Create = GUICtrlCreateButton("Create Conf", 384, 8, 75, 17) Global $Prev = GUICtrlCreateButton("Preview", 552, 8, 75, 17, 0) Global $Clean = GUICtrlCreateButton("Clean", 648, 8, 75, 17, 0) GUICtrlSetBkColor(-1, 0xFF0000) GUICtrlSetTip(-1, "17") Global $Send = GUICtrlCreateButton("Send", 728, 8, 75, 17, 0) GUICtrlSetBkColor(-1, 0x00FF00) Global $Edit1 = GUICtrlCreateEdit("", 0, 123, 835, 385) GUICtrlSetData(-1, "Edit1") Global $Group1 = GUICtrlCreateGroup("Configurações", 0, 0, 289, 105) Global $Label2 = GUICtrlCreateLabel("SMTP:", 32, 16, 37, 17) Global $Label3 = GUICtrlCreateLabel("SSL:", 40, 32, 27, 17) Global $Label4 = GUICtrlCreateLabel("List:", 48, 48, 23, 17) Global $Label5 = GUICtrlCreateLabel("from:", 40, 64, 27, 17) Global $Label6 = GUICtrlCreateLabel("user / pass:", 8, 80, 60, 17) Global $Label7 = GUICtrlCreateLabel("$state1", 72, 16, 39, 17) Global $Label8 = GUICtrlCreateLabel("$state1", 72, 32, 39, 17) Global $Label9 = GUICtrlCreateLabel("$state1", 72, 48, 39, 17) Global $Label10 = GUICtrlCreateLabel("$state1", 72, 64, 39, 17) Global $Label11 = GUICtrlCreateLabel("$state1", 72, 80, 39, 17) GUICtrlCreateGroup("", -99, -99, 1, 1) Global $Label1 = GUICtrlCreateLabel("Subject:", 296, 96, 43, 17) Global $Sub = GUICtrlCreateInput("Sub", 344, 96, 121, 21) Global $MenuItem2 = GUICtrlCreateMenu("File") Global $MenuItem5 = GUICtrlCreateMenuItem("Confs", $MenuItem2) Global $MenuItem4 = GUICtrlCreateMenuItem("Menssage", $MenuItem2) Global $MenuItem3 = GUICtrlCreateMenuItem("exit", $MenuItem2) Global $MenuItem1 = GUICtrlCreateMenu("About") Global $MenuItem7 = GUICtrlCreateMenuItem("Licence", $MenuItem1) Global $MenuItem6 = GUICtrlCreateMenuItem("Autors", $MenuItem1) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Local $Read[7] , $Decrypted[7] Func _Fload() $Passwd = "InboB6?" $FileInput = FileOpenDialog("Inbox project file open",@DesktopDir,"Inbox Conf (*.conf)") $Read[1] = FileReadLine ($FileInput,1) $Read[2] = FileReadLine ($FileInput,2) $Read[3] = FileReadLine ($FileInput,3) $Read[4] = FileReadLine ($FileInput,4) $Read[5] = FileReadLine ($FileInput,5) $Read[6] = FileReadLine ($FileInput,6) $Read[7] = FileReadLine ($FileInput,7) $Decrypted[1] =_StringEncrypt(0,$Read[1],$Passwd,2) $Decrypted[2] =_StringEncrypt(0,$Read[2],$Passwd,2) $Decrypted[3] =_StringEncrypt(0,$Read[3],$Passwd,2) $Decrypted[4] =_StringEncrypt(0,$Read[4],$Passwd,2) $Decrypted[5] =_StringEncrypt(0,$Read[5],$Passwd,2) $Decrypted[6] = _StringEncrypt(0,$Read[6],$Passwd,2) $Decrypted[7] =_StringEncrypt(0,$Read[7],$Passwd,2) If $Decrypted[1] = -1 Then $State[1] = "ERROR!" Else $State[1] = "OK" EndIf If $Decrypted[2] = -1 Then $State[2] = "ERROR!" Else $State[2] = "OK" EndIf If $Decrypted[3] = -1 Then $State[3] = "ERROR!" Else $State[3] = "OK" EndIf If $Decrypted[4] = -1 Then $State[4] = "ERROR!" Else $State[4] = "OK" EndIf If $Decrypted[5] = -1 Then $State[4] = "ERROR!" Else $State[4] = "OK" EndIf If $Decrypted[6] = -1 Then $State[5] = "ERROR!" Else $State[5] = "OK" EndIf If $Decrypted[7] = -1 Then $State[5] = "ERROR!" Else $State[5] = "OK" EndIf EndFunc Func _ESPM($s_SmtpServer = $Decrypted[1] , $s_FromName = $Decrypted[4], $s_FromAddress = $Decrypted[5], $s_ToAddress = "jdoe@computer4u.com", $s_Subject = GUICtrlRead($Sub), $as_Body = GUICtrlRead($Edit1), $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = FileRead($Decrypted[3]) $s_Importance="Low", $s_Username = $Decrypted[6], $s_Password = $Decrypted[7], $IPPort = 25 , $ssl = $sslcheck) Local $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]) ConsoleWrite('@@ Debug(62) : $S_Files2Attach = ' & $S_Files2Attach & @LF & '>Error code: ' & @error & @LF) ;### Debug Console If FileExists($S_Files2Attach[$x]) Then $objEmail.AddAttachment ($S_Files2Attach[$x]) Else ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF) 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 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") = 0 $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 ; 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 $objEmail.Fields.Update ; Sent the Message $objEmail.Send If @error Then SetError(2) Return $oMyRet[1] EndIf $objEmail="" EndFunc ;==>_INetSmtpMailCom While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Load _Fload() Case $Create Create() Case $Prev $Fileoutput = FileSaveDialog ("Message preview",@DesktopDir,"HTML Files (*.html)") FileWrite($Fileoutput,$Edit1) MsgBox (0,"Done","File Saved") Case $Clean GUICtrlSetData ($Edit1,"") Case $Send If $Decrypted[2] = 0 Then $sslcheck = 0 EndIf If $Decrypted[2] = 1 Then $sslcheck = 1 _ESpm() EndSwitch WEnd
sahsanu Posted May 12, 2011 Posted May 12, 2011 (edited) i code using one a UDF but i got several problems... If you explain the problems it should be easy to help you ;-) Anyway, if yo need to send an email authenticating the user, then you should change the 0 by 1 here: $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 0 ; change this to 1 Edit: You forgot to add an EndIf before call _ESpm() function. You are using functions like _StringEncrypt and _Pathfull but didn't add their includes (file.au3 & string.au3). Yo are calling as well to function Create() but you have not defined it. An advice, pay attention to errors shown by Scite, you will know what is going wrong in your script. Edit2: Uff uff, you need a deep review to your code. You are declaring arrays as $state[5] but you are using $state[1]....$state[5] that is wrong because arrays start at 0 not 1 so $state[5] does not exists. More info in Arrays wiki section. To avoid to change a lot of numbers on your code just declare it as $state[6]. Same for $read and $decrypted arrays (Local $Read[8] , $Decrypted[8]). Review twice how function works and take a look to the example. You are neither calling it nor defining it in the right way. Also you forgot to add MyErrFunc() and declare their variables as global. One more thing: Global $Label7 = GUICtrlCreateLabel("$state1", 72, 16, 39, 17) Global $Label7 = GUICtrlCreateLabel($state[1], 72, 16, 39, 17) and so on... Yes, you need to spend some time to fix your errors. Edited May 12, 2011 by sahsanu
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