NELyon Posted July 13, 2006 Share Posted July 13, 2006 #include <Inet.au3> $s_SmtpServer = "smtp.aol.com" $s_FromName = "Me" $s_FromAddress = "me@thisplace.com" $s_ToAddress = "nmyster94@yahoo.com" $s_Subject = "test" dim $as_body[2] $as_body[0] = "tesing" $as_body[1] = "it works" $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 I get error code 4 (Unable to open socket). Does anyone know what is wrong? Link to comment Share on other sites More sharing options...
Developers Jos Posted July 13, 2006 Developers Share Posted July 13, 2006 #include <Inet.au3> $s_SmtpServer = "smtp.aol.com" $s_FromName = "Me" $s_FromAddress = "me@thisplace.com" I get error code 4 (Unable to open socket). Does anyone know what is wrong? Are you using an AOL account and connection? Often providers only allow own members to use their SMTP servers to avoid spam... 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...
NELyon Posted July 13, 2006 Author Share Posted July 13, 2006 (edited) ok. i guess that explains why i couldn't use it in outlook either EDIT: do you know where a free smtp server is? Edited July 13, 2006 by codemyster Link to comment Share on other sites More sharing options...
jjohn Posted July 21, 2006 Share Posted July 21, 2006 #include <Inet.au3> $s_SmtpServer = "smtp.aol.com" $s_FromName = "Me" $s_FromAddress = "me@thisplace.com" $s_ToAddress = "nmyster94@yahoo.com" $s_Subject = "test" dim $as_body[2] $as_body[0] = "tesing" $as_body[1] = "it works" $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 I get error code 4 (Unable to open socket). Does anyone know what is wrong? Try this code below, I got it from previous search in this forum and found it did'nt work, so i make my modification, finally it did for me, hope it will work for you too. expandcollapse popupOpt("MustDeclareVars", 1) Dim $sData,$hSocket #cs ;example If _SendSMTPMail("smtp.mail.yahoo.com", _ "me@host.com", _ "youfirstbuddy@host.com, yoursecondbuddy@host.com, yourthirdbuddy@host.com", _ "Test email", _ "This is a test email") Then MsgBox(0, "_SendSMTP", "Message sent!") EndIf #ce Func _SendSMTPMail($sServer, $sSender, $sRecipients, $sSubject, $sBody) Local $aRcptList Local $nRcptOK = 0 Local $bSent = False Local $n ; Start TCP services If Not TCPStartup() Then Return False ; Connect to SMTP server $hSocket = TCPConnect(TCPNameToIP($sServer), 25) If $hSocket <> -1 Then ; Read 220 response from server flexitime() If StringLeft($sData, 3) = "220" Then $sData = "HELO " & @ComputerName & @CRLF ; Send HELO to server If TCPSend($hSocket, $sData) > 0 Then ; Receive 250 response from server flexitime() If StringLeft($sData, 3) = "250" Then $sData = "MAIL FROM: <" & $sSender & ">" & @CRLF ; Send MAIL FROM command to server If TCPSend($hSocket, $sData) > 0 Then ; Receive 250 response from server flexitime() If StringLeft($sData, 3) = "250" Then $aRcptList = StringSplit($sRecipients, ",") For $n = 1 To $aRcptList[0] $sData = "RCPT TO: <" & StringStripWS($aRcptList[$n], 8) & ">" & @CRLF ; Send RCPT TO command to server If TCPSend($hSocket, $sData) > 0 Then ; Receive 250 response from server flexitime() If StringLeft($sData, 3) = "250" Then $nRcptOK += 1 EndIf Next ; Continue if at least 1 recipient was accepted If $nRcptOK > 0 Then $sData = "DATA" & @CRLF ; Send DATA command to server If TCPSend($hSocket, $sData) > 0 Then ; Receive 354 response from server flexitime() If StringLeft($sData, 3) = "354" Then $sData = StringFormat("To: %s\r\nFrom: %s\r\n" & _ "Subject: %s\r\n" & _ "Date: %02d/%02d/%d %02d:%02d:%02d\r\n", _ $sRecipients, $sSender, $sSubject, _ @MDAY, @MON, @YEAR, @HOUR, @MIN, @SEC) ; Send message HEADER If TCPSend($hSocket, $sData) > 0 Then $sData = @CRLF & $sBody & @CRLF & @CRLF & "." & @CRLF ; Send message BODY If TCPSend($hSocket, $sData) > 0 Then ; Receive 250 response from server flexitime() If StringLeft($sData, 3) = "250" Then $bSent = True TCPSend($hSocket, 'QUIT' & @CRLF) Sleep(100) EndIf; QUIT this mail session EndIf; Send message BODY and end of message indicator EndIf; Send message HEADER EndIf; Receive 354 response from server EndIf; Send DATA command to server EndIf; Continue if at least 1 recipient was accepted EndIf; Receive 250 response from server EndIf; Send MAIL FROM command to server EndIf; Receive 250 response from server EndIf; Send HELO to server EndIf; Read 220 response from server ; Close TCP socket TCPCloseSocket($hSocket) EndIf ; Shutdown TCP services TCPShutdown() Return $bSent EndFunc Func flexitime() $sData = "" While 1 $sData = TCPRecv($hSocket, 1024) If $sData Then ExitLoop WEnd Return $sData EndFunc Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 21, 2006 Moderators Share Posted July 21, 2006 Wow, you'll love Arrays!! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Balachander K Posted July 26, 2006 Share Posted July 26, 2006 (edited) Oh Yeah!! It works......Good one...Thanks jjohn. File Attachment option can be added?? -Bala Edited July 26, 2006 by Balachander K Link to comment Share on other sites More sharing options...
AzKay Posted July 26, 2006 Share Posted July 26, 2006 I got them both to work, _INetSmtpMail & _INetSmtpMailCom, Took me awhile to figure out, the first one, had to be the smtp for your isp ^^; # MY LOVE FOR YOU... IS LIKE A TRUCK- # 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