DarkHo Posted May 25, 2010 Share Posted May 25, 2010 Hi im trying to make a email script but i get error 4 thats the 4 - Unable to create socket under _INetSmpt in help file but i cant fix it.. can some one help me ? expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <INet.au3> #Region ### START Koda GUI section ### Form= Dim $as_Body[2] $s_SmtpServer = "smtp.gmail.com" $s_FromName = "My Name" $s_FromAddress = "mymail@gmail.com" $s_ToAddress = "mymail@gmail.com" $Form1 = GUICreate("Mail Tester v1.0", 200, 150) $Input1 = GUICtrlCreateInput("", 64, 24, 121, 21) $s_Subject = GUICtrlCreateLabel("Subject:", 23, 27, 36, 17) $Line1 = GUICtrlCreateInput("", 64, 56, 121, 21) $Label2 = GUICtrlCreateLabel("Line1:", 30, 59, 28, 17) $Line2 = GUICtrlCreateInput("", 64, 80, 121, 21) $Label3 = GUICtrlCreateLabel("Line2:", 30, 84, 28, 17) $Button1 = GUICtrlCreateButton("Send", 112, 110, 73, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $as_Body[0] = GUICtrlRead($Line1) $as_Body[1] = GUICtrlRead($Line2) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 $Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body) $err = @error If $Response = 1 Then MsgBox(0, "Success!", "Mail sent") Else MsgBox(0, "Error!", "Mail failed with error code " & $err) EndIf EndSwitch WEnd Someone ? Link to comment Share on other sites More sharing options...
99ojo Posted May 25, 2010 Share Posted May 25, 2010 Hi, you have to authenticate before sending. See this post and take the _INetSmtpMailCom () function. http://www.autoitscript.com/forum/index.php?showtopic=96313&st=0&p=692425&hl=smtp%20gmailcom&fromsearch=1&#entry692425 ;-)) Stefan Tip: I found this in forum search with smtp gmail.com..... Link to comment Share on other sites More sharing options...
DarkHo Posted May 25, 2010 Author Share Posted May 25, 2010 Cant get one answer to fix it Link to comment Share on other sites More sharing options...
99ojo Posted May 25, 2010 Share Posted May 25, 2010 (edited) Hi, try this and put in Username and password: expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ;#include <INet.au3> #Include<file.au3> #Region ### START Koda GUI section ### Form= Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") Dim $as_Body[2] $s_SmtpServer = "smtp.gmail.com" $s_FromName = "My Name" $s_FromAddress = "mymail@gmail.com" $s_ToAddress = "mymail@gmail.com" $Importance ="Normal" $Username = "******" ; username for the account used from where the mail gets sent - REQUIRED -> put in your gmail account user $Password = "********" ; password for the account used from where the mail gets sent - REQUIRED -> the password for user above $IPPort=465 ; GMAIL port used for sending the mail $ssl=1 $Form1 = GUICreate("Mail Tester v1.0", 200, 150) $Input1 = GUICtrlCreateInput("", 64, 24, 121, 21) $s_Subject = GUICtrlCreateLabel("Subject:", 23, 27, 36, 17) $Line1 = GUICtrlCreateInput("", 64, 56, 121, 21) $Label2 = GUICtrlCreateLabel("Line1:", 30, 59, 28, 17) $Line2 = GUICtrlCreateInput("", 64, 80, 121, 21) $Label3 = GUICtrlCreateLabel("Line2:", 30, 84, 28, 17) $Button1 = GUICtrlCreateButton("Send", 112, 110, 73, 25, $WS_GROUP) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $as_Body[0] = GUICtrlRead($Line1) $as_Body[1] = GUICtrlRead($Line2) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ;$Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body) ;$err = @error $rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, GuiCtrlRead ($s_Subject), $as_Body, "", "", "", $Importance, $Username, $Password, $IPPort, $ssl) If @error Then MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc) Else MsgBox(0, "Error!", "Mail failed with error code " & $err) EndIf EndSwitch WEnd Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0) 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 : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console If FileExists($S_Files2Attach[$x]) Then ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF) .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") = 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 ; 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 ; ; ; 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 ;-)) Stefan @edit: Reviewing code you might try: Global $as_body.... $as_body = GuiCtrlRead ($line1) & @CRLF & GuiCtrlRead ($line2) instead of Global $as_body [2].... $as_Body[0] = GUICtrlRead($Line1) $as_Body[1] = GUICtrlRead($Line2) Edited May 25, 2010 by 99ojo Link to comment Share on other sites More sharing options...
Developers Jos Posted May 25, 2010 Developers Share Posted May 25, 2010 (edited) What have you changed in your originally posted script to apply the suggestion? Jos ps: Stick to this thread in stead of "shopping around" Edited May 25, 2010 by Jos 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...
Developers Jos Posted May 25, 2010 Developers Share Posted May 25, 2010 Hi,try this and put in Username and password:-snip;-))StefanYou forgot the fries... 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...
DarkHo Posted May 25, 2010 Author Share Posted May 25, 2010 (edited) can some one simple cod or give me help t that code is like over 200 lines and i dont know what it does so Helpp plz Simple code help Edited May 25, 2010 by DarkHo Link to comment Share on other sites More sharing options...
Developers Jos Posted May 25, 2010 Developers Share Posted May 25, 2010 can some one simple cod or give me help t that code is like over 200 lines and i dont know what it does so Helpp plz Simple code help If you show that you at least have taken the time to read the initial post we will... and do not fall in the same trap as you did a while ago. (yeap I remember ) 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...
99ojo Posted May 25, 2010 Share Posted May 25, 2010 Hi, the sauce for the fries (frittjes special...) Some paste and copy error, formerly in school we call it transfer task. S ince you post not all of your code, my glasbowl shows me: If @error Then MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc) Else ;MsgBox(0, "Error!", "Mail failed with error code " & $err) -> paste and copy error... MsgBox (0,"Success!", "Sucessfully sent Mail!") EndIf ;-)) Stefan Link to comment Share on other sites More sharing options...
DarkHo Posted May 25, 2010 Author Share Posted May 25, 2010 Hi, the sauce for the fries (frittjes special...) Some paste and copy error, formerly in school we call it transfer task. S ince you post not all of your code, my glasbowl shows me: If @error Then MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc) Else ;MsgBox(0, "Error!", "Mail failed with error code " & $err) -> paste and copy error... MsgBox (0,"Success!", "Sucessfully sent Mail!") EndIf ;-)) Stefan I posted the hall code in the first post Link to comment Share on other sites More sharing options...
Developers Jos Posted May 25, 2010 Developers Share Posted May 25, 2010 (edited) I posted the hall code in the first postNo you did not post the modifications you made after you read about the suggestion. Now show some effort reading the given replies by Stefan and the link he referred to. Edited May 25, 2010 by Jos 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