Saturday, February 5, 2011

JavaScript-friendly alternative to the f(x) = y JScript idiom that's used when setting CDO.Message options

I have an ASP page written in JScript that sends e-mails using CDO.Message. For specifying an SMTP server (and other options) I'm doing something like this:

mail.Configuration.Fields.Item(
    "http://schemas.microsoft.com/cdo/configuration/smtpserver") =
    "smtp.example.com";

Now, here comes the catch. I have this code in a stand-alone include file that I include in an HTML page as JavaScript so that I can run unit tests against it in a browser (using JsUnit etc.). I have JavaScript mock objects (Server, Request, etc.) that create a mock ASP environment for the included JScript code. The only problem I have left is with the CDO.Message option setting. Since the f(x) = y syntax that's used in the above code excerpt is not valid JavaScript (invalid left-hand operand), I can't run this piece of code (as it is) within a browser. I'm currently simply bypassing it in my unit test with a conditional that detects whether the environment is truly ASP.

I don't think that there's a JavaScript workaround to this. I'm looking for an alternative syntax (that may use the ActiveX interfaces differently) to setting CDO.Message options that would also be syntactically valid JavaScript.

  • I figured out the answer when looking at the C++ code example at http://msdn.microsoft.com/en-us/library/ms526318(EXCHG.10).aspx.

    The solution is to make the assignment explicitly to the Value property:

    mail.Configuration.Fields.Item(
        "http://schemas.microsoft.com/cdo/configuration/smtpserver").Value =
        "smtp.example.com";
    

    This way, the code above is valid JavaScript than can be tested with a mock Configuration object.

    From Ates Goral

0 comments:

Post a Comment