Hi Guyz i am very new to coding and Batch files,
was checking few forums on what a batch file can actually do and i am not able to locate or co relate what i wanted with the posts which i have seen,
my requirement is
1. i wanted the batch file to look on a folder and find the total number of files that got accumulated for a day, and find is there any file which is less than or equal to 1024bytes(1KB)
2 once this is done i wanted a email to send via the SMTP outgoing mail server to a particular email with details.
could locate this could be achieved via Java... but due to some constraints looking this on windows DOS batch file...ANy help is appreciated
Many thanks
Ashok
CAN A BATCH FILE CAPABLE TO DO THE BELOW
Moderator: DosItHelp
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: CAN A BATCH FILE CAPABLE TO DO THE BELOW
you can use a vbscript
If you can't seem to send email, can always try using tools such as blat (for emailing)
Code: Select all
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\myFolder")
strTo= "recipient@mail.com"
strFrom="sender@mail.com"
strSubject="Subject of mail"
strAccountID="user"
strPassword="pass"
strSMTPServer="smtp.server.com"
strSMTPPort=25
n=Now
For Each myFiles In objFolder.Files
'within the last 24 hours
If DateDiff("h",myFiles.DateLastModified,n) <= 24 Then
If myFiles.Size < 1024 Then
WScript.Echo myFiles.Size , myFiles.Name
SendMail strTo,strFrom,strSubject,strMessage,strAccountID,strPassword,strSMTPServer,strSMTPPort
End If
End If
Next
' send email using public mail servers
Function SendMail( strFrom, strSendTo, strSubject, strMessage , strUser, strPassword, strSMTP,strSMTPPort )
Set oEmail = CreateObject("CDO.Message")
'configure message
With oEmail.Configuration.Fields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTP
.item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic
.item("http://schemas.microsoft.com/cdo/configuration/sendusername") = strUser
.item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strPassword
.item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = strSMTPPort
.Update
End With
' build message
With oEmail
.From = strFrom
.To = strSendTo
.Subject = strSubject
.TextBody = strMessage
End With
' send message
On Error Resume Next
oEmail.Send
If Err Then
WScript.Echo "SendMail Failed:" & Err.Description
End If
End Function
If you can't seem to send email, can always try using tools such as blat (for emailing)
Re: CAN A BATCH FILE CAPABLE TO DO THE BELOW
I like the VBS script for emailing. You can also include a setting for SSL (and attach a file) which would allow the user to email from Gmail etc.
Re: CAN A BATCH FILE CAPABLE TO DO THE BELOW
Hi ghostmachine4,
Really appreciate your response, I am no way related to scripting but on seeing your VB script below it is really understandable thank you very much,
my constraint with regards to this the requirement is for a customer end system and any new application cannot be installed over there, I believe we need VB compiler to run your script on that system ! is it the case ?
do we have any options of doing it without a any external application installation( so no JDK , VB etc)
thanks
Ashok
Really appreciate your response, I am no way related to scripting but on seeing your VB script below it is really understandable thank you very much,
my constraint with regards to this the requirement is for a customer end system and any new application cannot be installed over there, I believe we need VB compiler to run your script on that system ! is it the case ?
do we have any options of doing it without a any external application installation( so no JDK , VB etc)
thanks
Ashok
-
- Posts: 319
- Joined: 12 May 2006 01:13
Re: CAN A BATCH FILE CAPABLE TO DO THE BELOW
cmeashok wrote:
do we have any options of doing it without a any external application installation( so no JDK , VB etc)
thanks
Ashok
vbscript (or rather the engine) comes installed with most versions of Windows unless its purposely turned off due to various reasons, eg security reasons. You do not need to download it from somewhere.
To run vbscript, using cscript command
Code: Select all
c:\> cscript //nologo myscript.vbs
OR you can wait for a DOS/batch solution. I believe the for loop has some parameters/option to indicate file size. As for emailing i am afraid you have to use some external tools for the job.
Re: CAN A BATCH FILE CAPABLE TO DO THE BELOW
Hi Ghostmachine4.
wow yes you are right, i was able to run the VB script on that system, i have just added my details on your orignal script but it seems to thow some errors, would you please check and advice is there is any issues
intially it gives me output like 24New text Document.txt(seems it is because there is new text Document.txt in the location sized 24bytes and it is just locating the 1 file eventhough we have multiple files and when i click the ok button it throws me the below error
Script : C:\Documents and Settings\w614838\Desktop\test.VBS
Line : 18
char : 13
Error : Type Mismatch: 'SendMail"
Code : 800A000D
Source : Microsoft VBScript runtime error
manythanks
wow yes you are right, i was able to run the VB script on that system, i have just added my details on your orignal script but it seems to thow some errors, would you please check and advice is there is any issues
Code: Select all
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Documents and Settings\w614838\Desktop")
strTo= "ashok.lakshminarayanan@vodafone.com"
strFrom="ashok.lakshminarayanan@vodafone.com"
strSubject="TEST 1KB FILE"
strSMTPServer="10.251.1.224"
strSMTPPort=25
n=Now
For Each myFiles In objFolder.Files
'within the last 24 hours
If DateDiff("h",myFiles.DateLastModified,n) <= 24 Then
If myFiles.Size <= 1024 Then
WScript.Echo myFiles.Size , myFiles.Name
SendMail strTo,strFrom,strSubject,strMessage,strSMTPServer,strSMTPPort
End If
End If
Next
intially it gives me output like 24New text Document.txt(seems it is because there is new text Document.txt in the location sized 24bytes and it is just locating the 1 file eventhough we have multiple files and when i click the ok button it throws me the below error
Script : C:\Documents and Settings\w614838\Desktop\test.VBS
Line : 18
char : 13
Error : Type Mismatch: 'SendMail"
Code : 800A000D
Source : Microsoft VBScript runtime error
manythanks
Last edited by Squashman on 20 Dec 2013 07:40, edited 1 time in total.
Reason: Added Code Tags
Reason: Added Code Tags