ezzetabi Posted September 17, 2004 Posted September 17, 2004 (edited) Untested with SMTP servers that need Authlogin. If someone can test I'd like to know if it is working. TESTED! YEAH!;Better code belowBlat can be downloaded here:http://prdownloads.sourceforge.net/blat/bl...te.zip?downloadMain site:http://www.blat.netYou need only the blat.exe file, copy it in the scrip folder. You need it if you use the uncompiled version. If you compile the script it will be FileInstall()ed so it is unneeded to keep it. Edited December 1, 2004 by ezzetabi
ezzetabi Posted September 17, 2004 Author Posted September 17, 2004 (edited) This script is great if you want to send few emails. If you need to send many it is maybe better Fileinstall() blat.exe in the begin of the script and delete it at the end. So it is not unpacked and deleted everytime but only once. If you want to do that remove, or comment, the lines 74 and 64 (considering the Func line as the first one) and put them in the AutoItStart/Exit() sections. Enjoy. Edited September 17, 2004 by ezzetabi
ezzetabi Posted September 17, 2004 Author Posted September 17, 2004 (edited) Already a modded version. This one may keep logs if needed: ;Better code below Edited October 6, 2004 by ezzetabi
ezzetabi Posted September 19, 2004 Author Posted September 19, 2004 Do you think I should improve this udf for checking the Blat errors? Thinking: Well... none answered so probably none care.
this-is-me Posted September 20, 2004 Posted September 20, 2004 (edited) Why not use bmail?Check here: http://www.beyondlogic.org/solutions/cmdli...cmdlinemail.htm Edited September 20, 2004 by this-is-me Who else would I be?
ezzetabi Posted September 20, 2004 Author Posted September 20, 2004 (edited) Because Blat is GNU, Bmail is not. And, overall, AFAIK Bmail does not allow auth login. Anyway, they are both command line mail sender. Why care about one or the other? Do you think I should improve this UDF in order to see Blat errors? Edited September 20, 2004 by ezzetabi
this-is-me Posted September 20, 2004 Posted September 20, 2004 Well, I am not the best one to ask, since I don't use it. So I said maybe. Who else would I be?
ezzetabi Posted September 20, 2004 Author Posted September 20, 2004 I am starting to think I should leave the board... :lol:
emmanuel Posted September 22, 2004 Posted September 22, 2004 Because Blat is GNU, Bmail is not. And, overall, AFAIK Bmail does not allow auth login. Anyway, they are both command line mail sender. Why care about one or the other? Do you think I should improve this UDF in order to see Blat errors? <{POST_SNAPBACK}>don't :cry: ezzetabi, yes, please do improve it to show errors, I knew this would be useful someday, just didn't know how... now that the idea of sms'ing with it comes up... I came searching for your UDF... "I'm not even supposed to be here today!" -Dante (Hicks)
emmanuel Posted September 22, 2004 Posted September 22, 2004 So, it's returning a 1 and @error's 0. Why? I don't see in the script where it'd return a 1... The log isn't generating anything either. I don't know weather the smtp requires auth or not... so, yeah, please, if you're willing, include parsing for blat errors? $r = _emailsend("server:25","email to","email from ","test","test","test.txt") $error = @error MsgBox(4096,'debug:' , '@error:' & $error);### Debug MSGBOX MsgBox(4096,'debug:' , '$r:' & $r);### Debug MSGBOX PS, I tried this from inside the firewall with corporate server as smtp and from outside with my server as smtp, mine at least, shouldn't require auth... "I'm not even supposed to be here today!" -Dante (Hicks)
ezzetabi Posted September 30, 2004 Author Posted September 30, 2004 Now that I am back I'll try to implement a check for blat errors. Ok, emmanuel.
ezzetabi Posted October 6, 2004 Author Posted October 6, 2004 Finally I started working on this.... And I discovered why you had this problem emmanuel. I tested this script in a Win98 machine and I forgot about the different way that Win98 and Win2000 manages " in @comspec! The stupiest error possible! Sorry! Sorry! Sorry! Sorry! Sorry! I'll correct and repost.
ezzetabi Posted October 6, 2004 Author Posted October 6, 2004 (edited) Still it does not out put the errors, but IT WORKS in WinXP. This time I did not tested in W98... The pain of people that travel a lot and uses different computers... ;Better code below Edited October 7, 2004 by ezzetabi
ezzetabi Posted October 7, 2004 Author Posted October 7, 2004 (edited) Finally, finally! This time if Blat have an error a windows appear showing the log. (Even if the user didn't ask for one.) This MsgBox have a 10 second timeout, so this Func won't stop automated scripts. If you ask for a logfile the existing log (if there) will be appended, not erased. So it is good also using this Func inside loops. Still, as I said before, there is no need to FileInstall() blat and delete it everytime if you need to use this Func many times, just move line 36 to AutoItStart section (remove the If/Then, of course) and line 95 to AutoItExit section. Enjoy. expandcollapse popupFunc _EmailSend($SMTP, $SENDER, $DEST, $SUBJECT, $TEXT, $LOGFILE) ; This func is a email sender. You just need to keep a copy of blat.exe ; in the script folder that will be FileInstall()ed and used. ; This script has been tested with the lite version, but it should works with other too. ; ; $SMTP is smtp address, use a : to divide the port and @lf to divide Auth login and pass. ; e.g. Server : mail.alpha.org:1845 ; AuthLogin: I am me ; AuthPass : Secret ; will become ; _EmailSend('mail.alpha.org:1845' & @lf & 'I am me' & @lf & 'Secret',...ect...) ; Of course Auth parameters must be used togheter and they are not mandatory. ; $SENDER is the sender address. ; $DEST is the destination addresses list. (comma separated) ; $SUBJECT is the Subject line. ; $TEXT is the email main text. It may be a filename or the message itself. ; - if you put directly the text use the @crlf as new line char. Be careful ; about the 4096 char limit of AutoIt lines. ; - if you use a file its content will become exatly the mail text, as binary. ; $LOGFILE is a filename where append the logfile. If omitted (left '') the log ; won't be created. ; Returns ; 1 All should be OK. ; -1 A blat error. The log is shown in a MsgBox with a 10 second timeout. ; -2 Badly formatted $SMTP ; -3 No @ in the sender address ; -4 No @ in the destination address ; -5 No text ; -6 No blat.exe in the script dir. Local $SMTP, $SENDER, $DEST, $SUBJECT, $TEXT, $LOGFILE, $LOG, $H = -1, $C, $E Local $SMTPSERVER, $AUTHLOGIN = '', $AUTHPASS = '' ;Install blat.exe (lite version) If Not FileInstall('blat.exe', @TempDir & '\~blattmp.exe', 1) Then Return -6 ;Check Smtp server If StringInStr($SMTP, @LF) Then $SMTP = StringSplit($SMTP, @LF) If Not $SMTP[0] = 3 Then Return -2 $SMTPSERVER = $SMTP[1] $AUTHLOGIN = $SMTP[2] $AUTHPASS = $SMTP[3] Else $SMTPSERVER = $SMTP EndIf ;Check addresses If Not StringInStr($SENDER, '@') Then Return -3 If Not StringInStr($DEST, '@') Then Return -4 ;Check subject If $SUBJECT = '' Then $SUBJECT = ' -ss ' Else $SUBJECT = ' -s "' & $SUBJECT & '" ' EndIf ;Check Text Select Case $TEXT = '' Return -5 Case Not FileExists($TEXT) FileDelete(@TempDir & '\~mailtext.tmp') FileWrite(@TempDir & '\~mailtext.tmp', $TEXT) $TEXT = (@TempDir & '\~mailtext.tmp') Case Else ; $Text file exists and will be used as mail text. EndSelect FileDelete(@TempDir & '\~maillog.txt') ;Sending! If IsArray($SMTP) Then;There is Authlogin $E = RunWait(@ComSpec & ' /c ""' & @TempDir & '\~blattmp.exe" "' & $TEXT & _ '" -to ' & $DEST & ' -binary -server ' & $SMTPSERVER & ' -log ' & @TempDir & _ '\~maillog.txt -timestamp -f ' & $SENDER & $SUBJECT & '-u ' & $AUTHLOGIN & _ ' -pw ' & $AUTHPASS & '"', @TempDir, @SW_HIDE) Else ;There is NOT Authlogin $E = RunWait(@ComSpec & ' /c ""' & @TempDir & '\~blattmp.exe" "' & $TEXT & _ '" -to ' & $DEST & ' -binary -server ' & $SMTPSERVER & ' -log ' & @TempDir & _ '\~maillog.txt -timestamp -f ' & $SENDER & $SUBJECT & '"', @TempDir, @SW_HIDE) EndIf $LOG = FileRead(@TempDir & '\~maillog.txt', FileGetSize(@TempDir & '\~maillog.txt')) If $LOGFILE <> '' Then $H = FileOpen($LOGFILE, 1) EndIf If $H <> - 1 Then;$H is -1 both if the user didn't ask for a logfile or ; if it is impossible to write in it. FileWrite($H, $LOG) FileClose($H) EndIf FileDelete(@TempDir & '\~maillog.txt') FileDelete(@TempDir & '\~mailtext.tmp') FileDelete(@TempDir & '\~blattmp.exe') If $E <> 0 Then MsgBox(16, 'Blat log. Errors.', $LOG, 10) Return -1 EndIf Return 1 EndFunc ;==>_EmailSend Edited October 7, 2004 by ezzetabi
ezzetabi Posted October 7, 2004 Author Posted October 7, 2004 (edited) Here the modded version that install blat.exe and delete it only once: expandcollapse popupFunc _EmailSend($SMTP, $SENDER, $DEST, $SUBJECT, $TEXT, $LOGFILE) ; This func is a email sender. You just need to keep a copy of blat.exe ; in the script folder that will be FileInstall()ed and used. ; This script has been tested with the lite version, but it should works with other too. ; ; $SMTP is smtp address, use a : to divide the port and @lf to divide Auth login and pass. ; e.g. Server : mail.alpha.org:1845 ; AuthLogin: I am me ; AuthPass : Secret ; will become ; _EmailSend('mail.alpha.org:1845' & @lf & 'I am me' & @lf & 'Secret',...ect...) ; Of course Auth parameters must be used togheter and they are not mandatory. ; $SENDER is the sender address. ; $DEST is the destination addresses list. (comma separated) ; $SUBJECT is the Subject line. ; $TEXT is the email main text. It may be a filename or the message itself. ; - if you put directly the text use the @crlf as new line char. Be careful ; about the 4096 char limit of AutoIt lines. ; - if you use a file its content will become exatly the mail text, as binary. ; $LOGFILE is a filename where append the logfile. If omitted (left '') the log ; won't be created. ; Returns ; 1 All should be OK. ; -1 A blat error. The log is shown in a MsgBox with a 10 second timeout. ; -2 Badly formatted $SMTP ; -3 No @ in the sender address ; -4 No @ in the destination address ; -5 No text ; -6 No installed blat.exe Local $SMTP, $SENDER, $DEST, $SUBJECT, $TEXT, $LOGFILE, $LOG, $H = -1, $C, $E Local $SMTPSERVER, $AUTHLOGIN = '', $AUTHPASS = '' If Not FileExists(@TempDir & '\~blattmp.exe') Then Return -6 ;Check Smtp server If StringInStr($SMTP, @LF) Then $SMTP = StringSplit($SMTP, @LF) If Not $SMTP[0] = 3 Then Return -2 $SMTPSERVER = $SMTP[1] $AUTHLOGIN = $SMTP[2] $AUTHPASS = $SMTP[3] Else $SMTPSERVER = $SMTP EndIf ;Check addresses If Not StringInStr($SENDER, '@') Then Return -3 If Not StringInStr($DEST, '@') Then Return -4 ;Check subject If $SUBJECT = '' Then $SUBJECT = ' -ss ' Else $SUBJECT = ' -s "' & $SUBJECT & '" ' EndIf ;Check Text Select Case $TEXT = '' Return -5 Case Not FileExists($TEXT) FileDelete(@TempDir & '\~mailtext.tmp') FileWrite(@TempDir & '\~mailtext.tmp', $TEXT) $TEXT = (@TempDir & '\~mailtext.tmp') Case Else ; $Text file exists and will be used as mail text. EndSelect FileDelete(@TempDir & '\~maillog.txt') ;Sending! If IsArray($SMTP) Then;There is Authlogin $E = RunWait(@ComSpec & ' /c ""' & @TempDir & '\~blattmp.exe" "' & $TEXT & _ '" -to ' & $DEST & ' -binary -server ' & $SMTPSERVER & ' -log ' & @TempDir & _ '\~maillog.txt -timestamp -f ' & $SENDER & $SUBJECT & '-u ' & $AUTHLOGIN & _ ' -pw ' & $AUTHPASS & '"', @TempDir, @SW_HIDE) Else ;There is NOT Authlogin $E = RunWait(@ComSpec & ' /c ""' & @TempDir & '\~blattmp.exe" "' & $TEXT & _ '" -to ' & $DEST & ' -binary -server ' & $SMTPSERVER & ' -log ' & @TempDir & _ '\~maillog.txt -timestamp -f ' & $SENDER & $SUBJECT & '"', @TempDir, @SW_HIDE) EndIf $LOG = FileRead(@TempDir & '\~maillog.txt', FileGetSize(@TempDir & '\~maillog.txt')) If $LOGFILE <> '' Then $H = FileOpen($LOGFILE, 1) EndIf If $H <> - 1 Then;$H is -1 both if the user didn't ask for a logfile or ; if it is impossible to write in it. FileWrite($H, $LOG) FileClose($H) EndIf FileDelete(@TempDir & '\~maillog.txt') FileDelete(@TempDir & '\~mailtext.tmp') If $E <> 0 Then MsgBox(16, 'Blat log. Errors.', $LOG, 10) Return -1 EndIf Return 1 EndFunc ;==>_EmailSend Func OnAutoItStart() ;Install blat.exe (lite version) FileInstall('blat.exe', @TempDir & '\~blattmp.exe', 1) EndFunc ;==>OnAutoItStart Func OnAutoItExit() ;Delete blat.exe FileDelete(@TempDir & '\~blattmp.exe') EndFunc ;==>OnAutoItExit Edited October 7, 2004 by ezzetabi
normeus Posted October 16, 2004 Posted October 16, 2004 windows 98 story: I got BLAT full version created a C:\BLAT222 folder copied your script to this directory and just added a call to the function at the beginning of the script $x=_EmailSend('misite.com' & @lf & 'normeus' & @lf & 'UhPassWord' ,'normeus@misite.com','youyu@yoursite.com',"how ","how you do",'c:/log.txt') ;and like every new user should do. I added a MsgBox for debugging MsgBox(4096,'debug:' , '$x:' & $x) ;### Debug MSGBOX @ComSpec didnt work; I guess windows 98 quotes differently!!! this line will work on 98: $E = RunWait(@ComSpec & ' /c "' & @TempDir & ....... <--- notice single double quotes after /c -------------------^ thanks for this nice Function also my smpt server sends my pc name and ip address so there will be no spam sending from this program kids http://www.autoitscript.com/autoit3/scite/...iTe4AutoIt3.exe
ezzetabi Posted October 16, 2004 Author Posted October 16, 2004 Corrected edition! expandcollapse popupFunc _EmailSend($SMTP, $SENDER, $DEST, $SUBJECT, $TEXT, $LOGFILE) ; This func is a email sender. You just need to keep a copy of blat.exe ; in the script folder that will be FileInstall()ed and used. ; This script has been tested with the lite version, but it should works with other too. ; ; $SMTP is smtp address, use a : to divide the port and @lf to divide Auth login and pass. ; e.g. Server : mail.alpha.org:1845 ; AuthLogin: I am me ; AuthPass : Secret ; will become ; _EmailSend('mail.alpha.org:1845' & @lf & 'I am me' & @lf & 'Secret',...ect...) ; Of course Auth parameters must be used togheter and they are not mandatory. ; $SENDER is the sender address. ; $DEST is the destination addresses list. (comma separated) ; $SUBJECT is the Subject line. ; $TEXT is the email main text. It may be a filename or the message itself. ; - if you put directly the text use the @crlf as new line char. Be careful ; about the 4096 char limit of AutoIt lines. ; - if you use a file its content will become exatly the mail text, as binary. ; $LOGFILE is a filename where append the logfile. If omitted (left '') the log ; won't be created. ; Returns ; 1 All should be OK. ; -1 A blat error. The log is shown in a MsgBox with a 10 second timeout. ; -2 Badly formatted $SMTP ; -3 No @ in the sender address ; -4 No @ in the destination address ; -5 No text ; -6 No installed blat.exe Local $SMTP, $SENDER, $DEST, $SUBJECT, $TEXT, $LOGFILE, $LOG, $H = -1, $C, $E Local $SMTPSERVER, $AUTHLOGIN = '', $AUTHPASS = '', $QUOTE = '' If Not FileExists(@TempDir & '\~blattmp.exe') Then Return -6 If @OSTYPE = 'WIN32_NT' Then $QUOTE = '"' ;Check Smtp server If StringInStr($SMTP, @LF) Then $SMTP = StringSplit($SMTP, @LF) If Not $SMTP[0] = 3 Then Return -2 $SMTPSERVER = $SMTP[1] $AUTHLOGIN = $SMTP[2] $AUTHPASS = $SMTP[3] Else $SMTPSERVER = $SMTP EndIf ;Check addresses If Not StringInStr($SENDER, '@') Then Return -3 If Not StringInStr($DEST, '@') Then Return -4 ;Check subject If $SUBJECT = '' Then $SUBJECT = ' -ss ' Else $SUBJECT = ' -s "' & $SUBJECT & '" ' EndIf ;Check Text Select Case $TEXT = '' Return -5 Case Not FileExists($TEXT) FileDelete(@TempDir & '\~mailtext.tmp') FileWrite(@TempDir & '\~mailtext.tmp', $TEXT) $TEXT = (@TempDir & '\~mailtext.tmp') Case Else ; $Text file exists and will be used as mail text. EndSelect FileDelete(@TempDir & '\~maillog.txt') ;Sending! If IsArray($SMTP) Then;There is Authlogin $E = RunWait(@ComSpec & ' /c ' & $quote & '"' & @TempDir & '\~blattmp.exe" "' & $TEXT & _ '" -to ' & $DEST & ' -binary -server ' & $SMTPSERVER & ' -log ' & @TempDir & _ '\~maillog.txt -timestamp -f ' & $SENDER & $SUBJECT & '-u ' & $AUTHLOGIN & _ ' -pw ' & $AUTHPASS & '"', @TempDir, @SW_HIDE) Else ;There is NOT Authlogin $E = RunWait(@ComSpec & ' /c ' & $quote & '"' & @TempDir & '\~blattmp.exe" "' & $TEXT & _ '" -to ' & $DEST & ' -binary -server ' & $SMTPSERVER & ' -log ' & @TempDir & _ '\~maillog.txt -timestamp -f ' & $SENDER & $SUBJECT & '"', @TempDir, @SW_HIDE) EndIf $LOG = FileRead(@TempDir & '\~maillog.txt', FileGetSize(@TempDir & '\~maillog.txt')) If $LOGFILE <> '' Then $H = FileOpen($LOGFILE, 1) EndIf If $H <> - 1 Then;$H is -1 both if the user didn't ask for a logfile or ; if it is impossible to write in it. FileWrite($H, $LOG) FileClose($H) EndIf FileDelete(@TempDir & '\~maillog.txt') FileDelete(@TempDir & '\~mailtext.tmp') If $E <> 0 Then MsgBox(16, 'Blat log. Errors.', $LOG, 10) Return -1 EndIf Return 1 EndFunc ;==>_EmailSend Func OnAutoItStart() ;Install blat.exe (lite version) FileInstall('blat.exe', @TempDir & '\~blattmp.exe', 1) EndFunc ;==>OnAutoItStart Func OnAutoItExit() ;Delete blat.exe FileDelete(@TempDir & '\~blattmp.exe') EndFunc ;==>OnAutoItExit
Matt @ MPCS Posted October 27, 2004 Posted October 27, 2004 In the following code: If $LOGFILE <> '' Then $H = FileOpen($LOGFILE, 1) EndIf If $H <> - 1 Then;$H is -1 both if the user didn't ask for a logfile or ; if it is impossible to write in it. FileWrite($H, $LOG) FileClose($H) EndIf Will - 1 (<dash><space><one>) be interpreted as -1 (<dash><one> or <negative one>)? *** Matt @ MPCS
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