Send mail from your bat files

Post image for Send mail from your bat files

by admin on November 17, 2009 · 0 comments

in BAT Files, Tips, Tools, Utility

Two weeks ago, I wrote about backing up a remote windows machine using Remote Desktop.

One thing lacking from this solution is email notification. How do we know if the backup job started? Or finished?

There is a free and open source tool that can be used to solve this problem, it is called blat. It consists of an executable, and a DLL.

You can find it at http://www.blat.net/

Send Mail Command Line

Download it, and extract the files to a place where your scripts run. In my case, I put it in c:\backups

To start, you will need an SMTP server that you have access to. That is probably the most difficult part of getting it to work – which means it is very easy to use.

If I just want to send a simple email that tells me a batch script has started, I could call it like this:

blat.exe -f batch@intelliadmin.com -to support@intelliadmin.com -server 192.168.1.1 -subject "Batch file started" -body "The very important batch script has started"

You have five required options to get your email to send:

-f [FROM] (This is the email address that the message will come from)
-to [TO] (This is the email address the message will be sent to)
-subject [SUBJECT] (Subject of the email. Uses quotes if you have spaces)
-body [BODY] (Body of email. Use quotes if you have spaces)
-server [SERVER] (IP Address or host name of the server)

That is for a simple message. Blat is filled with powerful options. For example, I could run a robocopy in my script, and redirect the output to a text file like this:

robocopy c:\backup \\server\c\backup >> output.txt

Then, when I send my notification I could attach the output text file to my email like this:

blat.exe -f batch@intelliadmin.com -to support@intelliadmin.com -server 192.168.1.1 -subject "Batch file started" -body "The very important batch script has completed" -attach c:\backup\output.txt

Once the command runs, the output will show up as an attachment in my inbox:

Send email cmd prompt

Like I said, it is loaded with options. Check it out, and when you do just type blat.exe -help to get the entire list of command line parameters.

{ 0 comments }

Date and time stamp in your batch files

November 11, 2009
Thumbnail image for Date and time stamp in your batch files

Update 11-12-2009: Looks like I made a typo. The date should be extracted with this line:
%date:~-4,4%%date:~-10,2%%date:~-7,2%
I have updated the article below, and thanks to Jim.G for noticing it!
There has been some activity recently in an old 2007 post I wrote about creating a date and time stamp in your batch files.
Well, the [...]

Read the full article →

Secure remote backup using remote desktop

November 5, 2009
Thumbnail image for Secure remote backup using remote desktop

I have been playing around with a few ideas on how to backup a server I have that is on the other side of town.
One of the problems I have is that the Internet provider blocks VPN traffic, and most other ways I know of getting a secure connection.
The one thing I can do [...]

Read the full article →

Windows 7 – Why your computer won’t go to sleep.

October 28, 2009
Thumbnail image for Windows 7 – Why your computer won’t go to sleep.

I have been playing around with the powercfg utility built into Windows 7, and I came across an interesting command line option:

powercfg /requests

What it does is list the reasons why your computer failed to go to sleep. I had the sleep function enabled on my desktop PC, and I noticed when I came back after [...]

Read the full article →

Connect to your VPN from the command line

October 21, 2009

I was setting up an offsite backup system for our source code. I wanted to use the VPN client within windows to connect the two machines.
One of the problems with this idea is that I only wanted this connection to be active while the source code was being copied
It turns out that it is very [...]

Read the full article →

Hide user accounts in Windows 7

October 14, 2009

Many times it is convenient to create a special administrator account that can be used for the task scheduler.
Unfortunately, if your Windows 7 computer is not joined to a domain, any accounts you create are shown at the start-up screen:

It would look better if you could remove this special account from the welcome screen, and [...]

Read the full article →

Windows 7 – "Identifying Network" (Resolved)

October 7, 2009

I was at a friends house last weekend. I found a very interesting problem with Windows 7. They had a laptop they just purchased in Taiwan, and no matter how they tried to connect it to their network, it would always say “Identifying Network”:

Now, in the screen shot it is the wireless network, but this [...]

Read the full article →

Free Tool – Suspend from the command line

September 22, 2009

I have a system task schedule that wakes up my system at night, runs a few backup processes…and then shuts the computer down.
What I really wanted it to do was to suspend, or hibernate. That way I can get back into my computer quick when I come back in the morning.
After searching around, I found [...]

Read the full article →

Get Windows Update on a DVD

September 16, 2009

I was reading an article at PCMag about PatchMateXP. They have had all the patches for XP on one convenient CD.
Unfortunately for PatchMateXP, this breaks a license with Microsoft and they shut themselves down before they got into legal trouble.
This got me thinking – is there a way to get MS Updates on DVD or [...]

Read the full article →

Windows XP vs Windows 7 – Who Won?

September 10, 2009

I installed Windows 7 on my ASUS Atom N270

Before I did that, I recorded how long it took to do a few things:
-Copying a 45 MB file over the network
-Boot Time
-Shutdown Time
-Memory used at idle, after startup
-IE Launch time
Then, after I installed Windows 7, I did the same, and recorded how long it took. [...]

Read the full article →