Codestone Ltd logo

Create a message with a single file attachment and send it with SMTPClient Object

// Example: CSMail JScript Example 2
// Summary: Create a message with a single file attachment and send it with the SMTPClient Object
// Usage:   cscript exjs02.js
//          or
//          wscript exjs02.js

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

// Attach a file
// Note - the Content-Type and Content-Transfer-Encoding fields will be set automatically
// by the control
MyMsg.Sections(2).AttachBodyFromFile("V:\\test\\tribbles.giff");  
              

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
SMTP.SendMessage(MyMsg);                      // Send the message
SMTP.Close();                                 // Close the server