We help IT Professionals succeed at work.

how to send a simple email from a batch program

delias
delias asked
on
need to send myself an email at the end of a batch job
Comment
Watch Question

Lee W, MVPTechnology and Business Process Advisor
Most Valuable Expert 2013

Commented:
You can use blat - http://www.blat.net/

Author

Commented:
i downloaded Blat. does not seem to work.
Lee W, MVPTechnology and Business Process Advisor
Most Valuable Expert 2013

Commented:
Ok... care to post an error message or some information I could use to help you?
Lee W, MVPTechnology and Business Process Advisor
Most Valuable Expert 2013

Commented:
Maybe a screen shot?

Author

Commented:
sorry, basically, I do not know how to use Blat. I downloaded it, expanded it..... not sure how to imbed it into a batch file........... trying to read docs now...
Thanks.
Technology and Business Process Advisor
Most Valuable Expert 2013
Commented:
Ok - almost everyone I've seen recommends blat, but it's the first time I'm trying it and I don't like it.  YEARS ago, I found gbmail.exe which I've always used and it's otherwise quite simple and a single file.  I can never find it anywhere online, so I've packaged it into my backup script download on my web site - go to www.lwcomputing.com/mysoftware.asp and download the backup script zip file.  Then you should find gbmail.exe in that - type gbmail /? for instructions on how to use it - it's pretty simple:

gbmail  [-v] -to <addres> [-file <filename>] [-h <smtp_server_name>]
        [-p <port_number>] [-from <addres>] [-cc <Cc:>] [-bcc <Bcc:>]
        [-s <Subject:>] [-t <timeout>]

And keep in mind, your antivirus software MAY block it if you don't allow it (some antivirus software will consider anything not "common" to be attempting to send spam and prevent it from working!
Lee W, MVPTechnology and Business Process Advisor
Most Valuable Expert 2013

Commented:
You can even use the backup batch file as an example of how to use gbmail - just review the code.

Author

Commented:
not able to view the backup bat source
Lee W, MVPTechnology and Business Process Advisor
Most Valuable Expert 2013

Commented:
Again, error messages?  Post screen shots?
Lee W, MVPTechnology and Business Process Advisor
Most Valuable Expert 2013

Commented:
Extract the file - don't just open the zip file - EXTRACT the contents to another folder - then you can open the .cmd file in notepad.  Look for the link starting with gbmail (use the text editor's find feature).

Because you asked about sending mail from a batch file, I assumed you had some experience with batch file to begin with.  If not, please go to www.robvanderwoude.com and review his information on batch scripting if you have problems understanding my batch file.
Top Expert 2009

Commented:
WOW.  Blat "IS" the way to go for me.  I have it deployed at my company's enterprise and use it throughout various scripting implementations (batch, WSH, SQL, etc...).  Not only do I send automated email to myself, but I send SMS text messages for the critical failures.

Maybe a few quick examples might help?  So for this example, let's assume the following:

1. Business DNS name suffix:
   a. Internet:  somebigbusiness.com
   b. Intranet:  sbb.local
2. SMTP mail server:  sbbsmtp.sbb.local
3. Known (to SMTP server) user email address:  cj@sbb.local

You always have to specify the 1) SMTP server, 2) the valid known sender UID, 3) a sendee UID, and some message.

So most very basic example with message text on the command line would be:
blat - -server "sbbsmtp.sbb.local" -f "cj@sbb.local" -to "cj@sbb.local" -s "subject text here" -body "batch script done."

Open in new window

Note the first dash "-" after the "blat" command is REQUIRED when using the command line switch -body.  The next basic alternative is to replace that first dash with the name of a file containing the text of the message to be sent and NOT using the -body command line switch.

The blat command continues with useful options such as -priority and -attach and can send email to anyone that your SMTP server would send to otherwise.

More examples (note: quoting (") is good, it keeps it in check, but isn't actually required until spaces are involved):
blat - -server "sbbsmtp.sbb.local" -f "cj@sbb.local" -to "cj@sbb.local, cj@hotmail.com" -s "multi user test" -body "this text email was sent to multiple users."

echo this test email was sent without the -body command line. > tmpfile.txt
blat tmpfile.txt -server "sbbsmtp.sbb.local" -f "cj@sbb.local" -to "cj@sbb.local, bunnybuns@hotmail.com" -s "message from file test"

blat - -server "sbbsmtp.sbb.local" -f "cj@sbb.local" -to "distriblist@sbb.local" -bcc "cj@sbb.local" -s "TPS reports are done" -body "The Earth is still rotating."

blat - -server "sbbsmtp.sbb.local" -f "cj@sbb.local" -to "cj@sbb.local" -cc "4155551212@txt.att.net" -s "bad mojo" -body "wake dude, it's bad m-kay?" -priority 1

Open in new window

And lastly, using a CONFIG FILE containing the following contents and named "blat.conf"

     ***** CUT HERE *****
     -server "sbbsmtp.sbb.local"
     -f "cj@sbb.local"
     -priority 0
     -to "cj@sbb.local"
     -s "drone status"
     -body "status is OK"
     ***** CUT HERE *****

blat - -of "blat.conf" -bcc "cj_cloud@gmail.com"

Open in new window