Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Need a batch script for sending mail from an NT server

137 views
Skip to first unread message

Anmol Dangwal

unread,
Jul 13, 2012, 4:48:03 AM7/13/12
to
Hello,

I need a batch script to send mail from a label inside batch file that should send mail to a particular group. I have created the below mentioned script to free up spcae fromk a drive so far. But i want that functionality to be added there in the script. Please help.
Note : The mail should be sent from the batch script only.

ping <servername> | find /i "Reply" >nul
if %errorlevel%==0 goto :pingsuccess
if %errorlevel%==1 goto :pingfailed

:pingsuccess
NET USE \\<servername> /USER:<User name> <pwd>
FREEDISK /s <servername> /U <Username> /P <Pwd> /D E: | FIND "bytes"
FOR /F "tokens=2" %%i IN ('FREEDISK /s <servername> /U <username> /P <pwd> /D E:') DO call :divgbe "%%i"

if %GBE% LSS 7 goto LowSpace else goto Spaceok
echo E=%GBE% GB

:divgbe
set gbe=%~1
set gbe=%gbe:,=%
REM crudely remove bytes and Kb
set gbe=%gbe:~0,-6%
REM Convert approx to Gb
set /a gbe=gbe*1000/1074
REM Extract whole part as all but last 3 digits
set big=%gbe:~0,-3%
REM Extract decimal part (last 3 digits and pad with zeros)
if [%big%]==[] set big=0
set small=000%gbe:~-3%
set small=%small:~-3%
set gbe=%big%.%small%
exit /b


:spaceok
echo There is enough Space in the drive.
end


:lowspace
call :script

:pingfailed
????? <here i want it to send an email>
exit /b

:script

foxidrive

unread,
Jul 13, 2012, 5:26:21 AM7/13/12
to
On Friday 13/07/2012 18:48, Anmol Dangwal wrote:
> Hello,
>
> I need a batch script to send mail

test this on your server.


::bat-email.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal
set vbsfile=bat-email.vbs
call :createVBS

:: defaults
set From=m...@here.com.au
set To=y...@lavabit.com
set Subj="email test %date% %time%"
set Body="did it work? %date% %time%"
set Serv=mail.server.com.au
set Auth=user
set Pass=pass

call :send %From% %To% %Subj% %Body% %Serv% %Auth% %Pass%
pause
del "%vbsfile%"
goto :EOF

:send
cscript.exe %vbsfile% %1 %2 %3 %4 %5 %6 %7
goto :EOF

:createVBS
del %vbsfile% 2>nul
set cdoSchema=http://schemas.microsoft.com/cdo/configuration
echo >>%vbsfile% Set objArgs = WScript.Arguments
echo >>%vbsfile% Set objEmail = CreateObject("CDO.Message")
echo >>%vbsfile% objEmail.From = objArgs(0)
echo >>%vbsfile% objEmail.To = objArgs(1)
echo >>%vbsfile% objEmail.Subject = objArgs(2)
echo >>%vbsfile% objEmail.Textbody = objArgs(3)
echo >>%vbsfile% ' objEmail.AddAttachment "%~f0"
echo >>%vbsfile% with objEmail.Configuration.Fields
echo >>%vbsfile% .Item ("%cdoSchema%/sendusing") = 2 ' not local, smtp
echo >>%vbsfile% .Item ("%cdoSchema%/smtpserver") = objArgs(4)
echo >>%vbsfile% .Item ("%cdoSchema%/smtpserverport") = 25
echo >>%vbsfile% .Item ("%cdoSchema%/smtpauthenticate") = 1 ' cdobasic
echo >>%vbsfile% .Item ("%cdoSchema%/sendusername") = objArgs(5)
echo >>%vbsfile% .Item ("%cdoSchema%/sendpassword") = objArgs(6)
echo >>%vbsfile% .Item ("%cdoSchema%/smtpusessl") = False
echo >>%vbsfile% .Item ("%cdoSchema%/smtpconnectiontimeout") = 25
echo >>%vbsfile% .Update
echo >>%vbsfile% end with
echo >>%vbsfile% objEmail.Send





--
Mic


0 new messages