Achilles Posted May 6, 2007 Share Posted May 6, 2007 I'm having no luck with this function. None of the servers work(I've tried the examples in the helpfile), and I have no idea where I would find one (I really have no idea what I'm talking about). If someone could please give me a IP address or a server that works that would be greatly appreciated! Or explain where to obtain one... My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
herewasplato Posted May 6, 2007 Share Posted May 6, 2007 ...(I really have no idea what I'm talking about)...If you don't mind the blind leading the blind then here goes my best guess:I think that all of the samples in the help file are fictitious server names. There are "open" SMTP servers on the NET, but that is probably not the best way to go. If your have an Internet Service Provider, then you might have a SMTP server that you can use. Search the support pages from your ISP for terms like SMTP and/or Outlook....hope this helps, I've never used the UDF... [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
anixon Posted May 6, 2007 Share Posted May 6, 2007 I am using both smtp and http (CDO.Message) as mail transporters without any problems. My ISP uses port 25 and ssl = 0. You issue may be related to a GMail type issue (Google) and similar sites which require a different port from memory 465. Also make sure that your script is registered with your Firewall. I always ping the site before I send an email to make sure that the server is active. You can use this codeCODE;Check Server $plserver = Ping(mail.yourmail.com, 250) If $plserver = 0 Then $message = " Mail Server NOT AVAILABLE" DisplayMessage() plexit() Else 'Do your thing' EndIf Cheers Ant.. Link to comment Share on other sites More sharing options...
Achilles Posted May 6, 2007 Author Share Posted May 6, 2007 I am using both smtp and http (CDO.Message) as mail transporters without any problems. My ISP uses port 25 and ssl = 0. You issue may be related to a GMail type issue (Google) and similar sites which require a different port from memory 465. Also make sure that your script is registered with your Firewall.I always ping the site before I send an email to make sure that the server is active. You can use this codeCODE;Check Server$plserver = Ping(mail.yourmail.com, 250)If $plserver = 0 Then $message = " Mail Server NOT AVAILABLE" DisplayMessage() plexit()Else ;'Do your thing'EndIfCheers Ant..I've tried using www.gmail.com and www.hotmail.com (since I have accounts with both) but with both cases it failed because it was " @ERROR = 4 - Unable to create socket" I have no idea what you were talking about in your first paragraph I'm pretty new to sending mail and all this stuff. Things I didn't understand: "stmp", "http (CDO.Message)", "My ISP uses port 25 and ssl = 0", "port from memory 465"... Hmm, I did get the last part though, so it's not my firewall stopping anything (I don't think... I added RunScript(beta) to the allowed list...) My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
Xenobiologist Posted May 6, 2007 Share Posted May 6, 2007 Hi, try this: expandcollapse popup#include <INet.au3> $s_SmtpServer = "mail.gmx.net" $s_FromName = "Mega" $s_FromAddress = "XXX" $s_ToAddress = "XXX" $s_Subject = "My Test UDF" $s_UName = "XXX" $s_PWD = "XXX" Dim $as_Body[2] $as_Body[0] = "Testing the new email udf" $as_Body[1] = "Second Line" $Response = _INetSmtpMailAuth ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_UName, $s_PWD, $s_Subject, $as_Body) ;~ $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 ;=============================================================================== ; ; Function Name: _INetSmtpMailAuth() ; Description: Sends an email using SMTP over TCP IP. ; Parameter(s): $s_SmtpServer - SMTP server to be used for sending email ; $s_FromName - Name of sender ; $s_FromAddress - eMail address of sender ; $s_ToAddress - Address that email is to be sent to ; $s_Username - Username for Authentication (bernd670) ; $s_Passwd - Password for Authentication (bernd670) ; $s_Subject - Subject of eMail ; $as_Body - Single dimension array containing the body of eMail as strings ; $s_helo - Helo identifier (default @COMPUTERNAME) sometime needed by smtp server ; $s_first - send before Helo identifier (default @CRLF) sometime needed by smtp server ; $b_trace - trace on a splash window (default 0 = no trace) ; Requirement(s): None ; Return Value(s): On Success - Returns 1 ; On Failure - 0 and sets ; @ERROR = 1 - Invalid Parameters ; @ERROR = 2 - Unable to start TCP ; @ERROR = 3 - Unable to resolve IP ; @ERROR = 4 - Unable to create socket ; @ERROR = 5x - Cannot open SMTP session ; @ERROR = 50x - Cannot send body ; @ERROR = 5000 - Cannot close SMTP session ; Authors: Original function to send email via TCP - Asimzameer ; Conversion to UDF - Walkabout ; Correction Helo, timeout, trace - Jpm ; Correction send before Helo - Jpm ; Include Authentication - bernd670 ; ;=============================================================================== Func _INetSmtpMailAuth($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Username, $s_Passwd, $s_Subject = "", $as_Body = "", $s_helo = "", $s_first="-1", $b_trace = 0) Local $v_Socket Local $s_IPAddress Local $i_Count Local $s_Send[9] Local $s_ReplyCode[9];Return code from SMTP server indicating success If $s_SmtpServer = "" Or $s_FromAddress = "" Or $s_ToAddress = "" Or $s_Username = "" Or $s_Passwd = "" Or $s_FromName = "" Or StringLen($s_FromName) > 256 Then SetError(1) Return 0 EndIf If $s_helo = "" Then $s_helo = @ComputerName If TCPStartup() = 0 Then SetError(2) Return 0 EndIf StringRegExp($s_SmtpServer, "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)") If @extended Then $s_IPAddress = $s_SmtpServer Else $s_IPAddress = TCPNameToIP($s_SmtpServer) EndIf If $s_IPAddress = "" Then TCPShutdown() SetError(3) Return 0 EndIf $v_Socket = TCPConnect($s_IPAddress, 25) If $v_Socket = -1 Then TCPShutdown() SetError(4) Return (0) EndIf $s_Send[0] = "EHLO " & $s_helo & @CRLF ;~ If StringLeft($s_helo,5) <> "EHLO " Then $s_Send[0] = "EHLO " & $s_helo & @CRLF $s_ReplyCode[0] = "250" $s_Send[1] = "AUTH LOGIN" & @CRLF $s_ReplyCode[1] = "334" $s_Send[2] = _Base64Encoding($s_Username) & @CRLF $s_ReplyCode[2] = "334" $s_Send[3] = _Base64Encoding($s_Passwd) & @CRLF $s_ReplyCode[3] = "235" $s_Send[4] = "MAIL FROM: <" & $s_FromAddress & ">" & @CRLF $s_ReplyCode[4] = "250" $s_Send[5] = "RCPT TO: <" & $s_ToAddress & ">" & @CRLF $s_ReplyCode[5] = "250" $s_Send[6] = "DATA" & @CRLF $s_ReplyCode[6] = "354" $s_Send[7] = "From: " & $s_FromName & " <" & $s_FromAddress & ">" & @CRLF & _ "To: " & "<" & $s_ToAddress & ">" & @CRLF & _ "Subject: " & $s_Subject & @CRLF & _ "Mime-Version: 1.0" & @CRLF & _ "Content-Type: text/plain; charset=US-ASCII" & @CRLF & _ @CRLF $s_ReplyCode[7] = "" $s_Send[8] = @CRLF & "." & @CRLF $s_ReplyCode[8] = "250" ; open stmp session If _SmtpSend($v_Socket, $s_Send[0], $s_ReplyCode[0], $b_trace, "220", $s_first) Then SetError(50) Return 0 EndIf ; send header For $i_Count = 0 To UBound($s_Send) - 2 If _SmtpSend($v_Socket, $s_Send[$i_Count], $s_ReplyCode[$i_Count], $b_trace) Then SetError(50 + $i_Count) Return 0 EndIf Next ; send body records (a record can be multiline : take care of a subline beginning with a dot should be ..) For $i_Count = 0 To UBound($as_Body) - 1 ; correct line beginning with a dot If StringLeft($as_Body[$i_Count], 1) = "." Then $as_Body[$i_Count] = "." & $as_Body[$i_Count] If _SmtpSend($v_Socket, $as_Body[$i_Count] & @CRLF, "", $b_trace) Then SetError(500 + $i_Count) Return 0 EndIf Next ; close the smtp session $i_Count = UBound($s_Send) - 1 If _SmtpSend($v_Socket, $s_Send[$i_Count], $s_ReplyCode[$i_Count], $b_trace) Then SetError(5000) Return 0 EndIf TCPCloseSocket($v_Socket) TCPShutdown() Return 1 EndFunc ;==>_INetSmtpMailAuth ;=============================================================================== ; ; Function Name: _Base64Encoding() ; Description: Kodiert eine Zeichenfolge mit dem Base64-Verfahren ; (http://de.wikipedia.org/wiki/Base64) ; Parameter(s): $String - Zeichenfolge die kodiert werden soll ; Requirement(s): None ; Return Value(s): Kodierte Zeichenfolge ; Authors: bernd670 ; ;=============================================================================== Func _Base64Encoding ($String) $strUmsetzung = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" $strRetValue = "" For $i = 1 To StringLen($String) Step 3 $strTok = StringMid($String,$i,3) Switch StringLen($strTok) Case 3 $iTokVal = (Asc(StringMid($strTok,1,1)) * 256 + _ Asc(StringMid($strTok,2,1))) * 256 + _ Asc(StringMid($strTok,3,1)) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $strRetValue &= $strTokCryt Case 2 $iTokVal = (Asc(StringMid($strTok,1,1)) * 256 + _ Asc(StringMid($strTok,2,1))) * 256 $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $strRetValue &= $strTokCryt & "=" Case 1 $iTokVal = Asc(StringMid($strTok,1,1)) * 65536 $iTokVal = BitShift($iTokVal,12) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $strRetValue &= $strTokCryt & "==" EndSwitch Next Return $strRetValue EndFunc So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
anixon Posted May 6, 2007 Share Posted May 6, 2007 I've tried using www.gmail.com and www.hotmail.com (since I have accounts with both) but with both cases it failed because it was " @ERROR = 4 - Unable to create socket" I have no idea what you were talking about in your first paragraph I'm pretty new to sending mail and all this stuff. Things I didn't understand: "stmp", "http (CDO.Message)", "My ISP uses port 25 and ssl = 0", "port from memory 465"... Hmm, I did get the last part though, so it's not my firewall stopping anything (I don't think... I added RunScript(beta) to the allowed list...)If you post the code that is not working it gives everyhone an opportunity to have a look and see where you have the issue. Ant.. Link to comment Share on other sites More sharing options...
anixon Posted May 6, 2007 Share Posted May 6, 2007 I stand to be corrected on these comments. I use smtp when my Notebook is connectivity via my networked mail server. I use CD0.Message where I have an internet connection but I am not logged onto my networked mail server connection (when I am out and about). If you have a look at the smtp code you do not pass the username or password as is the case with CDO.Message. In addition CDO.Message also supports File Attachments. In the case of ssl you would set this to "1" when using httpS. Cheers Ant Link to comment Share on other sites More sharing options...
Achilles Posted May 6, 2007 Author Share Posted May 6, 2007 (edited) This annoying me, but I'm making progress (thanks to much help!) I now get error code 53 when using Mega's code. This is the first part... #include <INet.au3> $s_SmtpServer = "mail.gmx.net" $s_FromName = "Piano_man" $s_FromAddress = "{my hotmail email}@hotmail.com" $s_ToAddress = "{my gmail email}@gmail.com" $s_Subject = "My Test UDF" $s_UName = "{my hotmail email}@hotmail.com" $s_PWD = "{my hotmail password}" Dim $as_Body[2] $as_Body[0] = "Testing the new email udf" $as_Body[1] = "Second Line" $Response = _INetSmtpMailAuth ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_UName, $s_PWD, $s_Subject, $as_Body) ;~ $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 Error code 50x means it "Cannot send body".. but I have no idea why it wouldn't be able to... @anixon: Are you using "CD0.Message" with autoit? 'Cause if you are I would greatly appreciate it if you showed me how to use it EDIT: I have success message box using the normal _INetSmtpMail (while using the "mail.gmx.net"), but I get no mail... Edited May 6, 2007 by Piano_Man My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
herewasplato Posted May 6, 2007 Share Posted May 6, 2007 Have you looked here?http://www.autoitscript.com/forum/index.ph...st&p=166575 [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
anixon Posted May 6, 2007 Share Posted May 6, 2007 This annoying me, but I'm making progress (thanks to much help!) I now get error code 53 when using Mega's code. This is the first part... #include <INet.au3> $s_SmtpServer = "mail.gmx.net" $s_FromName = "Piano_man" $s_FromAddress = "{my hotmail email}@hotmail.com" $s_ToAddress = "{my gmail email}@gmail.com" $s_Subject = "My Test UDF" $s_UName = "{my hotmail email}@hotmail.com" $s_PWD = "{my hotmail password}" Dim $as_Body[2] $as_Body[0] = "Testing the new email udf" $as_Body[1] = "Second Line" $Response = _INetSmtpMailAuth ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_UName, $s_PWD, $s_Subject, $as_Body) ;~ $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 Error code 50x means it "Cannot send body".. but I have no idea why it wouldn't be able to... @anixon: Are you using "CD0.Message" with autoit? 'Cause if you are I would greatly appreciate it if you showed me how to use it EDIT: I have success message box using the normal _INetSmtpMail (while using the "mail.gmx.net"), but I get no mail... Try this CODE;http Processor Func httpProcessData() $count = $count + 1 $counter = StringRight($count, 1) $msgpause = 1 $message = " Processed: " & $count DisplayMessage() $addrdata = StringLower($data1) _IsValidEmail($addrdata) If @error = 1 Then $badaddr = FileOpen(@ScriptDir & "\datafiles\InvalidData\" & (@YDAY) & "Addr.csv", 9) FileWriteLine($badaddr, $data1 & "," & $data2 & "," & $data3 & "," & $data4 & "," & $data5 & "," & _ $data6 & "," & $Sfile & "," & "HTTP" & "," & @HOUR & ":" & @MIN & ":" & @SEC) FileClose($badaddr) $dcount = $dcount + 1 Else $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $objMessage = ObjCreate("CDO.Message") With $objMessage .Subject = $data2 .Sender = $fromaddr .From = "" ;Not Used Causes Errors .To = $data1 .TextBody = $data3 & @CRLF & $data4 & @CRLF & $data5 & @CRLF & $data6 EndWith With $objMessage.Configuration.Fields .Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $isp ; <== SMTP SERVER .Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 .Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $ispuser ; <== SMTP USERNAME .Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $isppw ; <== SMTP PASSWORD .Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $ispport .Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 If $ispssl = 0 Then .Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False Else .Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True EndIf .Update EndWith $objMessage.Send If $plserverErr = 0 Then $mailed = FileOpen(@ScriptDir & "\datafiles\Mailed\" & (@YDAY) & "Sent.csv", 9) FileWriteLine($mailed, $data1 & "," & $data2 & "," & $data3 & "," & $data4 & "," & $data5 & "," & _ $data6 & "," & $Sfile & "," & "HTTP" & "," & @HOUR & ":" & @MIN & ":" & @SEC) $mcount = $mcount + 1 $counter = StringRight($count, 1) If $mcount = 1 Or $counter = 0 Then $msgpause = 0 $message = " SENDING Mail" DisplayMessage() EndIf Else $failed = FileOpen(@ScriptDir & "\datafiles\FailedMail\" & (@YDAY) & "NotSent.csv", 9) FileWriteLine($failed, $data1 & "," & $data2 & "," & $data3 & "," & $data4 & "," & $data5 & "," & _ $data6 & "," & $Sfile & "," & "HTTP" & "," & @HOUR & ":" & @MIN & ":" & @SEC) FileClose($failed) $fcount = $fcount + 1 If $count = 1 Or $counter = 0 Then $msgpause = 0 $message = " HTTP Processing has FAILED: " DisplayMessage() EndIf EndIf EndIf EndFunc ;==>httpProcessData ;Set HTTP Error Func MyErrFunc() $plserverErr = 1 EndFunc ;==>MyErrFunc ;Email Address Check Subroutine Func _IsValidEmail($sEmail) If StringRegExp($sEmail, "^([a-zA-Z0-9_\-])([a-zA-Z0-9_\-\.]*)@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|" & _ "((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$") Then Return 1 Return SetError(1, 0, 0) EndFunc ;==>_IsValidEmail ;Reset Mail Counters Func resetcounters() $dcount = "" $mcount = "" $fcount = "" $count = "" $cmail = "" EndFunc ;==>resetcounters Link to comment Share on other sites More sharing options...
Achilles Posted May 7, 2007 Author Share Posted May 7, 2007 Have you looked here?http://www.autoitscript.com/forum/index.ph...st&p=166575YAY, thanks for that link! My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list] Link to comment Share on other sites More sharing options...
herewasplato Posted May 7, 2007 Share Posted May 7, 2007 (edited) YAY, thanks for that link!You are welcome.I hope that it works for you.I have never used it..... Edited May 7, 2007 by herewasplato [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Xenobiologist Posted May 7, 2007 Share Posted May 7, 2007 This annoying me, but I'm making progress (thanks to much help!) I now get error code 53 when using Mega's code. This is the first part... #include <INet.au3> $s_SmtpServer = "mail.gmx.net" $s_FromName = "Piano_man" $s_FromAddress = "{my hotmail email}@hotmail.com" $s_ToAddress = "{my gmail email}@gmail.com" $s_Subject = "My Test UDF" $s_UName = "{my hotmail email}@hotmail.com" $s_PWD = "{my hotmail password}" Dim $as_Body[2] $as_Body[0] = "Testing the new email udf" $as_Body[1] = "Second Line" $Response = _INetSmtpMailAuth ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_UName, $s_PWD, $s_Subject, $as_Body) ;~ $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 Error code 50x means it "Cannot send body".. but I have no idea why it wouldn't be able to... @anixon: Are you using "CD0.Message" with autoit? 'Cause if you are I would greatly appreciate it if you showed me how to use it EDIT: I have success message box using the normal _INetSmtpMail (while using the "mail.gmx.net"), but I get no mail... HI, using hotmail you have to use this smtp I guess mx1.hotmail.com not the gmx one. So long, Mega Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
FreeBeing Posted September 11, 2011 Share Posted September 11, 2011 Hi, try this: expandcollapse popup#include <INet.au3> $s_SmtpServer = "mail.gmx.net" $s_FromName = "Mega" $s_FromAddress = "XXX" $s_ToAddress = "XXX" $s_Subject = "My Test UDF" $s_UName = "XXX" $s_PWD = "XXX" Dim $as_Body[2] $as_Body[0] = "Testing the new email udf" $as_Body[1] = "Second Line" $Response = _INetSmtpMailAuth ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_UName, $s_PWD, $s_Subject, $as_Body) ;~ $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 ;=============================================================================== ; ; Function Name: _INetSmtpMailAuth() ; Description: Sends an email using SMTP over TCP IP. ; Parameter(s): $s_SmtpServer - SMTP server to be used for sending email ; $s_FromName - Name of sender ; $s_FromAddress - eMail address of sender ; $s_ToAddress - Address that email is to be sent to ; $s_Username - Username for Authentication (bernd670) ; $s_Passwd - Password for Authentication (bernd670) ; $s_Subject - Subject of eMail ; $as_Body - Single dimension array containing the body of eMail as strings ; $s_helo - Helo identifier (default @COMPUTERNAME) sometime needed by smtp server ; $s_first - send before Helo identifier (default @CRLF) sometime needed by smtp server ; $b_trace - trace on a splash window (default 0 = no trace) ; Requirement(s): None ; Return Value(s): On Success - Returns 1 ; On Failure - 0 and sets ; @ERROR = 1 - Invalid Parameters ; @ERROR = 2 - Unable to start TCP ; @ERROR = 3 - Unable to resolve IP ; @ERROR = 4 - Unable to create socket ; @ERROR = 5x - Cannot open SMTP session ; @ERROR = 50x - Cannot send body ; @ERROR = 5000 - Cannot close SMTP session ; Authors: Original function to send email via TCP - Asimzameer ; Conversion to UDF - Walkabout ; Correction Helo, timeout, trace - Jpm ; Correction send before Helo - Jpm ; Include Authentication - bernd670 ; ;=============================================================================== Func _INetSmtpMailAuth($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Username, $s_Passwd, $s_Subject = "", $as_Body = "", $s_helo = "", $s_first="-1", $b_trace = 0) Local $v_Socket Local $s_IPAddress Local $i_Count Local $s_Send[9] Local $s_ReplyCode[9];Return code from SMTP server indicating success If $s_SmtpServer = "" Or $s_FromAddress = "" Or $s_ToAddress = "" Or $s_Username = "" Or $s_Passwd = "" Or $s_FromName = "" Or StringLen($s_FromName) > 256 Then SetError(1) Return 0 EndIf If $s_helo = "" Then $s_helo = @ComputerName If TCPStartup() = 0 Then SetError(2) Return 0 EndIf StringRegExp($s_SmtpServer, "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)") If @extended Then $s_IPAddress = $s_SmtpServer Else $s_IPAddress = TCPNameToIP($s_SmtpServer) EndIf If $s_IPAddress = "" Then TCPShutdown() SetError(3) Return 0 EndIf $v_Socket = TCPConnect($s_IPAddress, 25) If $v_Socket = -1 Then TCPShutdown() SetError(4) Return (0) EndIf $s_Send[0] = "EHLO " & $s_helo & @CRLF ;~ If StringLeft($s_helo,5) <> "EHLO " Then $s_Send[0] = "EHLO " & $s_helo & @CRLF $s_ReplyCode[0] = "250" $s_Send[1] = "AUTH LOGIN" & @CRLF $s_ReplyCode[1] = "334" $s_Send[2] = _Base64Encoding($s_Username) & @CRLF $s_ReplyCode[2] = "334" $s_Send[3] = _Base64Encoding($s_Passwd) & @CRLF $s_ReplyCode[3] = "235" $s_Send[4] = "MAIL FROM: <" & $s_FromAddress & ">" & @CRLF $s_ReplyCode[4] = "250" $s_Send[5] = "RCPT TO: <" & $s_ToAddress & ">" & @CRLF $s_ReplyCode[5] = "250" $s_Send[6] = "DATA" & @CRLF $s_ReplyCode[6] = "354" $s_Send[7] = "From: " & $s_FromName & " <" & $s_FromAddress & ">" & @CRLF & _ "To: " & "<" & $s_ToAddress & ">" & @CRLF & _ "Subject: " & $s_Subject & @CRLF & _ "Mime-Version: 1.0" & @CRLF & _ "Content-Type: text/plain; charset=US-ASCII" & @CRLF & _ @CRLF $s_ReplyCode[7] = "" $s_Send[8] = @CRLF & "." & @CRLF $s_ReplyCode[8] = "250" ; open stmp session If _SmtpSend($v_Socket, $s_Send[0], $s_ReplyCode[0], $b_trace, "220", $s_first) Then SetError(50) Return 0 EndIf ; send header For $i_Count = 0 To UBound($s_Send) - 2 If _SmtpSend($v_Socket, $s_Send[$i_Count], $s_ReplyCode[$i_Count], $b_trace) Then SetError(50 + $i_Count) Return 0 EndIf Next ; send body records (a record can be multiline : take care of a subline beginning with a dot should be ..) For $i_Count = 0 To UBound($as_Body) - 1 ; correct line beginning with a dot If StringLeft($as_Body[$i_Count], 1) = "." Then $as_Body[$i_Count] = "." & $as_Body[$i_Count] If _SmtpSend($v_Socket, $as_Body[$i_Count] & @CRLF, "", $b_trace) Then SetError(500 + $i_Count) Return 0 EndIf Next ; close the smtp session $i_Count = UBound($s_Send) - 1 If _SmtpSend($v_Socket, $s_Send[$i_Count], $s_ReplyCode[$i_Count], $b_trace) Then SetError(5000) Return 0 EndIf TCPCloseSocket($v_Socket) TCPShutdown() Return 1 EndFunc ;==>_INetSmtpMailAuth ;=============================================================================== ; ; Function Name: _Base64Encoding() ; Description: Kodiert eine Zeichenfolge mit dem Base64-Verfahren ; (http://de.wikipedia.org/wiki/Base64) ; Parameter(s): $String - Zeichenfolge die kodiert werden soll ; Requirement(s): None ; Return Value(s): Kodierte Zeichenfolge ; Authors: bernd670 ; ;=============================================================================== Func _Base64Encoding ($String) $strUmsetzung = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" $strRetValue = "" For $i = 1 To StringLen($String) Step 3 $strTok = StringMid($String,$i,3) Switch StringLen($strTok) Case 3 $iTokVal = (Asc(StringMid($strTok,1,1)) * 256 + _ Asc(StringMid($strTok,2,1))) * 256 + _ Asc(StringMid($strTok,3,1)) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $strRetValue &= $strTokCryt Case 2 $iTokVal = (Asc(StringMid($strTok,1,1)) * 256 + _ Asc(StringMid($strTok,2,1))) * 256 $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $strRetValue &= $strTokCryt & "=" Case 1 $iTokVal = Asc(StringMid($strTok,1,1)) * 65536 $iTokVal = BitShift($iTokVal,12) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $strRetValue &= $strTokCryt & "==" EndSwitch Next Return $strRetValue EndFunc So long, Mega I have fixed little things : _SmtpSend changed to __SmtpSend (underscore added). Also, I think it's useful to change SMTP port if we want, so I added it : expandcollapse popup;=============================================================================== ; ; Function Name: _INetSmtpMailAuth() ; Description: Sends an email using SMTP over TCP IP. ; Parameter(s): $s_SmtpServer - SMTP server to be used for sending email ; $s_SmtpPort - SMTP server port to use (25, 587, 465, or anything your ISP need) ; $s_FromName - Name of sender ; $s_FromAddress - eMail address of sender ; $s_ToAddress - Address that email is to be sent to ; $s_Username - Username for Authentication (bernd670) ; $s_Passwd - Password for Authentication (bernd670) ; $s_Subject - Subject of eMail ; $as_Body - Single dimension array containing the body of eMail as strings ; $s_helo - Helo identifier (default @COMPUTERNAME) sometime needed by SMTP server ; $s_first - send before Helo identifier (default @CRLF) sometime needed by SMTP server ; $b_trace - trace on a splash window (default 0 = no trace) ; Requirement(s): None ; Return Value(s): On Success - Returns 1 ; On Failure - 0 and sets ; @ERROR = 1 - Invalid Parameters ; @ERROR = 2 - Unable to start TCP ; @ERROR = 3 - Unable to resolve IP ; @ERROR = 4 - Unable to create socket ; @ERROR = 5x - Cannot open SMTP session ; @ERROR = 50x - Cannot send body ; @ERROR = 5000 - Cannot close SMTP session ; Authors: Original function to send email via TCP - Asimzameer ; Conversion to UDF - Walkabout ; Correction Helo, timeout, trace - Jpm ; Correction send before Helo - Jpm ; Include Authentication - bernd670 ; ;=============================================================================== Func _INetSmtpMailAuth($s_SmtpServer, $s_SmtpPort, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Username, $s_Passwd, $s_Subject = "", $as_Body = "", $s_helo = "", $s_first="-1", $b_trace = 0) Local $v_Socket Local $s_IPAddress Local $i_Count Local $s_Send[9] Local $s_ReplyCode[9];Return code from SMTP server indicating success If $s_SmtpServer = "" Or $s_FromAddress = "" Or $s_ToAddress = "" Or $s_Username = "" Or $s_Passwd = "" Or $s_FromName = "" Or StringLen($s_FromName) > 256 Then SetError(1) Return 0 EndIf If $s_helo = "" Then $s_helo = @ComputerName If TCPStartup() = 0 Then SetError(2) Return 0 EndIf StringRegExp($s_SmtpServer, "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)") If @extended Then $s_IPAddress = $s_SmtpServer Else $s_IPAddress = TCPNameToIP($s_SmtpServer) EndIf If $s_IPAddress = "" Then TCPShutdown() SetError(3) Return 0 EndIf $v_Socket = TCPConnect($s_IPAddress, $s_SmtpPort) If $v_Socket = -1 Then TCPShutdown() SetError(4) Return (0) EndIf $s_Send[0] = "EHLO " & $s_helo & @CRLF ;~ If StringLeft($s_helo,5) <> "EHLO " Then $s_Send[0] = "EHLO " & $s_helo & @CRLF $s_ReplyCode[0] = "250" $s_Send[1] = "AUTH LOGIN" & @CRLF $s_ReplyCode[1] = "334" $s_Send[2] = _Base64Encoding($s_Username) & @CRLF $s_ReplyCode[2] = "334" $s_Send[3] = _Base64Encoding($s_Passwd) & @CRLF $s_ReplyCode[3] = "235" $s_Send[4] = "MAIL FROM: <" & $s_FromAddress & ">" & @CRLF $s_ReplyCode[4] = "250" $s_Send[5] = "RCPT TO: <" & $s_ToAddress & ">" & @CRLF $s_ReplyCode[5] = "250" $s_Send[6] = "DATA" & @CRLF $s_ReplyCode[6] = "354" $s_Send[7] = "From: " & $s_FromName & " <" & $s_FromAddress & ">" & @CRLF & _ "To: " & "<" & $s_ToAddress & ">" & @CRLF & _ "Subject: " & $s_Subject & @CRLF & _ "Mime-Version: 1.0" & @CRLF & _ "Content-Type: text/plain; charset=US-ASCII" & @CRLF & _ @CRLF $s_ReplyCode[7] = "" $s_Send[8] = @CRLF & "." & @CRLF $s_ReplyCode[8] = "250" ; open stmp session If __SmtpSend($v_Socket, $s_Send[0], $s_ReplyCode[0], $b_trace, "220", $s_first) Then SetError(50) Return 0 EndIf ; send header For $i_Count = 0 To UBound($s_Send) - 2 If __SmtpSend($v_Socket, $s_Send[$i_Count], $s_ReplyCode[$i_Count], $b_trace) Then SetError(50 + $i_Count) Return 0 EndIf Next ; send body records (a record can be multiline : take care of a subline beginning with a dot should be ..) For $i_Count = 0 To UBound($as_Body) - 1 ; correct line beginning with a dot If StringLeft($as_Body[$i_Count], 1) = "." Then $as_Body[$i_Count] = "." & $as_Body[$i_Count] If __SmtpSend($v_Socket, $as_Body[$i_Count] & @CRLF, "", $b_trace) Then SetError(500 + $i_Count) Return 0 EndIf Next ; close the SMTP session $i_Count = UBound($s_Send) - 1 If __SmtpSend($v_Socket, $s_Send[$i_Count], $s_ReplyCode[$i_Count], $b_trace) Then SetError(5000) Return 0 EndIf TCPCloseSocket($v_Socket) TCPShutdown() Return 1 EndFunc ;==>_INetSmtpMailAuth ;=============================================================================== ; ; Function Name: _Base64Encoding() ; Description: Kodiert eine Zeichenfolge mit dem Base64-Verfahren ; (http://de.wikipedia.org/wiki/Base64) ; Parameter(s): $String - Zeichenfolge die kodiert werden soll ; Requirement(s): None ; Return Value(s): Kodierte Zeichenfolge ; Authors: bernd670 ; ;=============================================================================== Func _Base64Encoding ($String) $strUmsetzung = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" $strRetValue = "" For $i = 1 To StringLen($String) Step 3 $strTok = StringMid($String,$i,3) Switch StringLen($strTok) Case 3 $iTokVal = (Asc(StringMid($strTok,1,1)) * 256 + _ Asc(StringMid($strTok,2,1))) * 256 + _ Asc(StringMid($strTok,3,1)) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $strRetValue &= $strTokCryt Case 2 $iTokVal = (Asc(StringMid($strTok,1,1)) * 256 + _ Asc(StringMid($strTok,2,1))) * 256 $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $strRetValue &= $strTokCryt & "=" Case 1 $iTokVal = Asc(StringMid($strTok,1,1)) * 65536 $iTokVal = BitShift($iTokVal,12) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) $iTokVal = BitShift($iTokVal,6) $strTokCryt = StringMid($strUmsetzung,(BitAND($iTokVal,63)) + 1,1) & $strTokCryt $strRetValue &= $strTokCryt & "==" EndSwitch Next Return $strRetValue EndFunc Thank you very much for your help, it had helped me, really. 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