Email from a batch file

I wrote a batch file that will back up certain users files on their computer.  Is it possible to have in the batch file a way to email the user that the backup took place?  If so could I get some examples?
HBMIAsked:
Who is Participating?
 
Steve KnightConnect With a Mentor IT ConsultancyCommented:
That relies on the registered email client to send a message, e.g. Outlook, Lotus Notes, etc.  Much better is to use a tool such as BLAT or a short VBScript to send a message direct to an SMTP server:

http://scripts.dragon-it.co.uk/links/email-from-batch

The above is a page of mine showing one method using the free BLAT tool and then at the bottom you've got a VBScript which you can amend in notepad, put it in the same dir and then call from batch file with

cscript //nologo sendmail.vbs

hth

Steve
0
 
exile1337Commented:
try this one


@ECHO OFF
SET ERRORS=0
:: Use your own mappings and search strings here
NET USE P: | FIND /I "%username%" >NUL 2>NUL
IF ERRORLEVEL 1 CALL :ErrorMsg P:
NET USE S: | FIND /I "system" >NUL 2>NUL
IF ERRORLEVEL 1 CALL :ErrorMsg S:
:: Create an e-mail message if any errors were detected
IF %ERRORS% GEQ 1 CALL :Mail
:: Clear variables used in this batch file
FOR %%A IN (BODY DATE ERRORS LINE MESSAGE TIME) DO SET %%A=
GOTO :EOF

:ErrorMsg
SET /A ERRORS = %ERRORS% + 1
NET USE %1 >NUL 2>NUL
IF ERRORLEVEL 1 (
	SET BODY=%BODY%%%0D%%0ADrive%%20%1%%20not%%20mapped
	GOTO :EOF
)
FOR /F "TOKENS=3* DELIMS= " %%A IN ('NET USE %1 ˆ| FIND "Local name"') DO SET MESSAGE=Drive%%20%%A%%20mapped%%20to%%20
:: Replacement of backslashes "\" by "%%5C"
:: prevents interpretation of "\n" as CR/LF
FOR /F "TOKENS=3,4* DELIMS=\ " %%A IN ('NET USE %1 ˆ| FIND "Remote name"') DO SET MESSAGE=%MESSAGE%%%5C%%5C%%A%%5C%%B
SET BODY=%BODY%%%0D%%0A%MESSAGE%
GOTO :EOF

:Mail
FOR /F "TOKENS=2*" %%A IN ('DATE/T') DO SET DATE=%%A
FOR /F %%A IN ('TIME/T') DO SET TIME=%%A
START mailto:helpdesk@ourdomain.com?subject=Drive%%20mapping%%20errorˆ&body=At%%20%DATE%,%%20%TIME%,%%20user%%20%USERNAME%%%20encountered%%20the%%20following%%20drive%%20mapping%%20error(s)%%20on%%20%COMPUTERNAME%:%%0D%%0A%BODY%
GOTO :EOF

Open in new window

0
 
Bill PrewCommented:
A recent question just addressed this, take a look at the link below for approaches.

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_27403190.html

~bp
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
Steve KnightIT ConsultancyCommented:
@billprew. Yes though it was a bit messy and drawn out and never really had any actual specific conclusion!
@exile1337.  In http:#37030766 why do you set DATE and TIME to blank?!


Anyway you have got some options now for how to do the emails.... a mailto: link, blat, or VBScript.  Do you need help with identifying the errors, in which case please let us see your script if you want help integrsating it.  Easiest option is to download sendmail.vbs file above (and attached here), edit it notepad for your address, text and smtp server and add  cscript //nologo sendmail.vbs to your script relating to finding an error.

Steve

 sendmail.vbs
0
 
Steve KnightIT ConsultancyCommented:
HBMI - did that help with what you needed?

Steve
0
 
Bill PrewCommented:
0
 
Bill PrewCommented:
Need any additional help on this question?

~bp
0
 
Steve KnightIT ConsultancyCommented:
Glad it helped.
thanks

Steve
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.