Keith Joubert logo - home.

Home
Contact

Binary Search
Sort Multiple Columns
Filing Functions
Extracting Excel data
Read and Write .csv files
Show Progress Messages
Send Automatic Email
Running under .hta
Setting Folder Attributes
Long-script warnings
Desktop Shortcut
ADODB & SQL queries


 

 
SEND  AUTOMATIC  EMAIL

How to send automatic email, in the background, using Javascript.  The following code requires MS Outlook to be installed on the PC running the program.

You can send a long (or short) body text and/or an attachment file/image. 

var bodyT = 'This is a long string .....'; // 'bodytext' can be a long string.
var atPath= 'C:\\Test\\1533.csv'; // 'attach' is the file '1533.csv' in this example.

function AutoMail(sendto,subject,bodytxt,attach){
  var theApp=new ActiveXObject("Outlook.Application");
  var theNameSpace=theApp.GetNameSpace("MAPI").CurrentUser;
  var theMailItem=theApp.CreateItem(0);
  theMailItem.Recipients.Add(sendto);
  theMailItem.Subject=(subject);
  theMailItem.Body=(bodytxt);
  theMailItem.Attachments.Add(attach);
  theMailItem.Send;
  theNameSpace.Logoff;
  theApp=null;
}

Usage:

AutoMail('someone@somewhere.com','Test AutoMail',bodyT,atPath);

TopTop