Codestone Ltd logo

Winbatch support for the Internet Mail Client Control Library

You can use the Internet Mail Client Control Library (CSMail) through the inbuilt COM/OLE support of the Winbatch programming langauge.

In most cases the standard release of CSMail will be all that you need. (You can download an evalution copy of the library here).

Restrictions in the Winbatch syntax and how to work around them

There are two restrictions in the Winbatch syntax which make coding with COM/OLE libraries a little more verbose than other automation enabled languages such as vbscript.

Winbatch Syntax Restriction 1 - Only single level of object model hierarchy is allowed in a single statement

This is nuisance when accessing hierarchical models; we might like to write:

messagebody=msg.Sections(1).Body

But Winbatch requires that we break it down as follows:

tmp=msg.Sections(1)
messagebody=tmp.Body

Winbatch Syntax Restriction 2 - Parentheses are not allowed on the left side of an assignment statement

To assign a value to an item in an COM/OLE collection we might like to write:

msg.To(1)="SSkinner@springfield"

Unfortunately Winbatch does not allow this syntax. Fortunately if the COM/OLE collection exposes standard automation collection methods we can work around this:

tmp=msg.To
tmp.Add("SSkinner@springfield")

With a couple of exceptions (for which a patch is available see below) all the collection objects in CSMail support standard OLE collection operations and so can be used in WinBatch.

Using the CSMail objects in Winbatch

You can create an instance of any of the CSMail objects with the Winbatch ObjectOpen function. - for example:

msg=ObjectOpen("CSMail.Message")

After creating an object you can access the properties and methods documented in the manual. (The manual is also included in the standard installation).

So, for example, to set the subject of the message we created above:

msg.Subject="Quick brown foxes causing chaos"

Then we can set the recipient and originator of the email:

tmp=msg.To
tmp.Add("SSkinner@springfield")

tmp=msg.From
tmp
.Add("EKrabappel@springfield")

To complete the message we need to add a message body:

tmp=msg.Sections
section
=tmp.Add
section
.Body="Now is the time for all good men to come to the aid of the party"

Finally we can create an SMTPClient object and send the message we just created:

smtp=ObjectOpen("CSMail.SMTPClient")
smtp.Connect("my.mail.server")
smtp.SendMessage(msg)
smtp.Close

Non standard collections in CSMail

There are a couple of collection properties in the CSMail object model which do not expose the full set of standard automation collection methods. Specifically these are the Option property of the Settings object and the Item property of the Header object.

While these collections are not always required in normal usage of the CSMail library we have created a patched version of the library with Winbatch-friendly alternatives. You can download the patched library below.

After downloading the patch you should replace the copy of csmail.dll created by the standard installation with the patched version. (The standard installation usually creates csmail.dll in C:\Program Files\Codestone Ltd\Codestone Internet Mail Client Library\CSMail.dll)

The patched library adds the following two methods to the library:

  • Settings.WBSetOption(Index,newVal) - allows you to set Settings.Option(Index)
  • Header.WBSetHeader(Index,newVal) - allows you to set Header(Index)

Downloads

download csmail.exe 1652224 bytes Mon Oct 5 05:50:56 2009 EDT Self extracting executable
download CSMail.dll 585728 bytes Tue Dec 27 09:44:48 2005 EST Winbatch patch for csmail