Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


DOS bat-file mail via Java

Posted on 2009-05-09
Medium Priority
Last Modified: 2013-11-24

I need to make a dos bat-file to shedule.
In this bat-file I call sqlplus to run a query that works fine.
The results of that query needs to be mailed to an address.
On the same machine I found an example of an old college. In his bat-file the last instruction is :
java -cp .;D:\BR\com\util\activation.jar;D:\BR\com\util\mail.jar com.util.CheckFile "D:\BR\LOG\UL3.bad" "mailadres@mail.du" "SQLLOADER" "111.x.111.xx" "Results of query
In the directory where I found his bat-file there is a diretory com\util with the files activation.jar, mail.jar and CheckFile.Class.
I copied this to my directory but it seems not to work (when executing the bat-file I receive an error on that mailing) . I have no experience with java at all.
I think that I may not copy the jar-file. But I need to install something? Also the Checkfile.Class I think I have to change this, but how can I do this. (With notepad it is rubbish)

Can someone give me a hint how I can solve this.

Question by:haezeban
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

ID: 24344765
just use the WSH smtp option, or something like this (from here:

@echo off & setlocal
:: set the temp file location
set tempmail=%temp%\tempmail.%random%.txt
:: echo the basic headers to the temp file
echo To: "Scripting Test" ^<^> > %tempmail%
echo From: "Me" ^<^> >> %tempmail%
echo Subject: Test2 >> %tempmail%
:: echo the blank line that separates the header from the body text
:: echo the body text to the temp file
echo First line of body text.>> %tempmail%
echo Second line of body text.>> %tempmail%
:: move the temp file to the mail pickup directory
:: adjust this location for your system
move %tempmail% c:\inetpub\mailroot\pickup
set tempmail=


Author Comment

ID: 24344992
IIS doesn't run on that machine. I don't see it in administrative tools and not under services.
I don'think I can se your script.
anyway thanks
LVL 71

Expert Comment

ID: 24345386
For commandline send mail, it's best to use BLAT ( It allows for many options including sending attachments, and needs nothing installed on the executing PC.
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!


Expert Comment

ID: 24345726
try this:
Set objEmail = CreateObject("CDO.Message")
objEmail.From = ""
objEmail.To = ""
objEmail.Subject = "subjkect"
objEmail.Textbody = "message"

If you have any MAPI client on the computer, it should work by using those settings.

Author Comment

ID: 24420603

I wrote a routine in C# and don't use anymore this javamail.
Thanks for help.

Accepted Solution

haezeban earned 0 total points
ID: 24421496
I wrote a little programm in C#, and don't uses JAVAMAIL anymore (this was blackbox to me).
it works almost (just need to post a new question but in another mailgroup).

The code :
using System;
using System.Web.Mail;
using System.IO;

namespace Mailer
      /// <summary>
      /// This Class sends emails with or without attachment(s).
      /// </summary>
      public class Mailer
            private MailMessage message;
            private bool problem = false;
            private string problemDescription = "";

            public bool Problem
                  get {return problem;}

            public string ProblemDescription
                  get      {return problemDescription;}

            public Mailer()
                  message = new MailMessage();

            public void sendMail(string to, string from, string subject, string body, string server, string attachment)
                        message.To = to;
                        message.From = from;
                        message.Subject = subject;
                        message.Body = body;
                        if (attachment.Length > 4)
                              if (File.Exists(attachment)) message.Attachments.Add(new MailAttachment(attachment));
                              SmtpMail.SmtpServer = server;
                        catch(System.Web.HttpException ehttp)
                              problem = true;
                              problemDescription = ehttp.Message + "\n\r";
                              problemDescription += ehttp.ToString();
                  catch(System.Exception e)
                        problem = true;
                        problemDescription = e.Message + "\n\r";
                        problemDescription += e.ToString();

Thanks to all experts

Featured Post


We will be discussing what Azure Stack is, how does it fit into the suit of offerings that Azure has currently, and where can it fit into your organizations technology stack. We will also be discussing limitations of the platform while covering various applicable scenarios.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question