Note that there are some explanatory texts on larger screens.

plurals
  1. POCDO CreateMHTMLBody locks the file in JScript
    primarykey
    data
    text
    <p>I'm making a JScript script that sends e-mail messages in HTML format via CDO. I have a message template in .html file, and I put some unique data into each message being sent. So, I create a copy of the original .html file for each message.</p> <p>The problem is that I cannot detele this temporary file from within script after sending the message. I've checked with ProcessExplorer, which process locks the file, and it is cscript.exe/wscript.exe (wichever is being used to run the script).</p> <p>Here is the example (simplified) code:</p> <pre><code>//------------------------------------------- var fso = new ActiveXObject("Scripting.FileSystemObject"); var BodyFileName = fso.GetAbsolutePathName(WScript.Arguments(3)); var BodyExtensionName = fso.GetExtensionName(BodyFileName) var BodyFile = fso.OpenTextFile(BodyFileName, 1); var Body = BodyFile.ReadAll(); BodyFile.Close(); //------------------------------------------- // Replace something in Body here //------------------------------------------- BodyFileName = fso.BuildPath(fso.GetParentFolderName(BodyFileName), fso.GetTempName() + "." + BodyExtensionName); var TmpBodyFile = fso.OpenTextFile(BodyFileName, 2, true); TmpBodyFile.Write(Body); TmpBodyFile.Close(); // Here ProcessExplorer shows that the file is closed //------------------------------------------- var objEmail = new ActiveXObject("CDO.Message"); objEmail.From = WScript.Arguments(0); objEmail.To = WScript.Arguments(1); objEmail.Subject = WScript.Arguments(2); objEmail.CreateMHTMLBody("file:///" + BodyFileName.replace("\\","/")); // Here the file is open again objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2; objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "192.168.0.1"; objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25; objEmail.Configuration.Fields.Update(); objEmail.Send(); objEmail = null; //------------------------------------------- // The following loop becomes endless for (;;) { try { fso.DeleteFile(BodyFileName, true); } catch(e) { WScript.Sleep(100); continue; } finally { } break; } //------------------------------------------- </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload