var wshShell = WScript.CreateObject( "WScript.Shell" );

var dbver = WScript.Arguments(0).toUpperCase();
var mailall = WScript.Arguments.Length > 1 && WScript.Arguments(1) == "mailall";

fac_send_mail_html("j.grootlipman@facilitor.nl");
if (mailall)
{
    fac_send_mail_html("e.groener@facilitor.nl");
    fac_send_mail_html("m.geerdink@facilitor.nl");
    fac_send_mail_html("k.reefman@facilitor.nl");
    //fac_send_mail_html("gijs.wassink@aareon.nl");
}
//fac_send_mail_html("glipman@home.nl");
//fac_send_mail_html("helpdesk@facilitor.nl");

WScript.Echo(new Date());
function fac_send_mail_html(adrTo,strSubj,strBody)
{
    strSubj = "ORA-errors in TestOracle " + new Date();
    strBody = "ORA-errors in TestOracle" ;
    strBody += "<br/>More details in z:\\Project\\FACILITOR\\BUILD\\DB" + dbver + "\\TEST_OUTPUT"
    strBody += "\n<br/><code>";
    while (!WScript.StdIn.AtEndOfStream)
    {
        strBody = strBody + WScript.StdIn.ReadAll();
    }
    strBody += "\n</code>";
    strBody = strBody.replace(/\n/g, "\n<br>")
    var objMail;

    var sch = "http://schemas.microsoft.com/cdo/configuration/"

    var iConf =  new ActiveXObject("CDO.Configuration")
    iConf.Fields(sch+"sendusing") = 2;
    //iConf.Fields(sch+"smtpserver") = "facws001";
    iConf.Fields(sch+"smtpserver") = "Smtprelay.ad.aareon.com";

    iConf.Fields(sch+"smtpserverport") = 25;
    iConf.Fields(sch+"smtpauthenticate") = 0; // anoniem
    iConf.Fields.Update();

    // create mail service object
    objMail = new ActiveXObject("CDO.Message");
    objMail.Configuration = iConf

    //var objAttachment = objMail.AddAttachment("diffwork_33.lst");
    //objAttachment.ContentTransferEncoding = "base64";

    WScript.Echo("E-mailing to " + adrTo);

    objMail.To = adrTo;
    objMail.From = "oracletest@oracletest.facilitor.nl";
    objMail.Subject = strSubj;
    objMail.HtmlBody = strBody;

    objMail.Send();
}
