Create a message containing all the files in a directory and send it with the SMTPClientObject
// Example: CSMail JScript Example 3
// Summary: Create a message containing all the files in a directory and
// send it with the SMTPClientObject
// Usage: cscript exvbs03.vbs
// or
// wscript exvbs03.vbs
MyMsg=new ActiveXObject("CSMail.Message"); // Create the message object
MyMsg.Subject="Medical Officer's Report"; // Set the message subject
MyMsg.To(1)="kirk@enterprise.com"; // Set the recipient...
MyMsg.From(1)="bones@enterprise.com"; // ... and the originator
MyMsg.Sections(1).Body="Its life Jim, but not as we know it.";
// Set the message body text
// See the Microsoft Windows Scripting Host Documentation for details
// of the FileSystemObject model
fso=new ActiveXObject("Scripting.FileSystemObject");
folder=fso.GetFolder("v:\\test");
fc = new Enumerator(folder.files); // Need an enumerator object in JScript!
for (; !fc.atEnd(); fc.moveNext()) { // Iterate through the files
WScript.echo(fc.item().Name); // Diagnostics (see WSH docs re wscript.echo)
s=MyMsg.Sections.Add(); // Create a new section in the current message
s.AttachBodyFromFile(fc.item().Path); // Attach the file
}
SMTP = new ActiveXObject("CSMail.SMTPClient"); // Create an SMTP Client Object
SMTP.Connect("127.0.0.1"); // Connect to the server - in this case the local machine
WScript.echo("Sending...");
SMTP.SendMessage(MyMsg); // Send the message
WScript.echo("Sent...");
SMTP.Close() // Close the server
|