Codestone Ltd logo

To, CC, BCC, ReplyTo, From, Sender and Subject Properties

// Example: CSMail JScript Example 8
// Summary: To, CC, BCC, ReplyTo, From, Sender and Subject Properties
// Usage:   cscript exjs08.vbs
//          or
//          wscript exjs08.vbs

// 1) Set the fields the easy way - through the properties

WScript.echo("First method");

MyMsg=new ActiveXObject("CSMail.Message");    // Create the message object

MyMsg.To(1)="kirk@enterprise.fed";            // Add first primary recipient
MyMsg.To(2)="spock@enterprise.fed";           // Add second primary recipient

MyMsg.CC(1)="checkov@enterprise.fed";         // Add first copy recipient
MyMsg.CC(2)="sulu@enterprise.fed";            // Add second copy recipient

MyMsg.BCC(1)="bones@enterprise.fed";          // Add first blind copy recipient
MyMsg.BCC(2)="scotty@enterprise.fed";         // Add second blind copy recipient

MyMsg.From(1)="uhura@enterpise.fed";          // Could have multiple Froms if we wanted
MyMsg.Sender(1)="uhura@enterpise.fed";        // Can only have one Sender
MyMsg.ReplyTo(1)="uhura@enterpise.fed";       

MyMsg.Subject="Message from Starfleet Headquarters";

// Note - setting these properties automatically updates appropriate Fields in the Messge Header collection
// Lets dump the Header to see whats happened-

// Show all the MIME message fields
// Show all the MIME message fields
WScript.echo("Dumping all MIME Fields:")
headers=new Enumerator(MyMsg.Header);

for (;!headers.atEnd();headers.moveNext()) {
  
WScript.echo(headers.item()+"="+MyMsg.Header(headers.item()));
  }


// 2) Set the properties the harder (?) way - through the Header OLE collection ...
WScript.echo("Second method");

myMsg=new ActiveXObject("CSMail.Message");      // Create  a new message object
myMsg.Header("To")="kirk@enterprise.fed,spock@enterprise.fed";
myMsg.Header("CC")="checkov@enterprise.fed,sulu@enterprise.fed";
myMsg.Header("BCC")="bones@enterprise.fed,scotty@enterprise.fed";
myMsg.Header("From")="uhura@enterpise.fed";
myMsg.Header("Sender")="uhura@enterpise.fed";
myMsg.Header("Reply-To")="uhura@enterpise.fed";
myMsg.Header("Subject")="Message from Starfleet Headquarters";

// Note - setting these properties automatically updates the appropriate properties
// Lets dump the properties to check...


WScript.echo("'To' recipients:");
address=new Enumerator(MyMsg.To);
for (;!address.atEnd();address.moveNext()) {
  
WScript.echo("--"+address.item());
  }

WScript.echo("'CC' recipients:");
address=new Enumerator(MyMsg.CC);
for (;!address.atEnd();address.moveNext()) {
  
WScript.echo("--"+address);
  }

WScript.echo("'BCC' recipients:")
address=new Enumerator(MyMsg.BCC);
for (;!address.atEnd();address.moveNext()) {
  
WScript.echo("--"+address);
  }

// etc.....