NEWMAIL OBJECT
The CDONTS NewMail object
|
When Microsoft Windows 2000 or NT4 with NT Option Pack is installed, the default setup includes Simple Mail Transfer Protocol (SMTP). Among other purposes, this can be used to provide email functions for web sites which use Active Server Pages (ASP). CDONTS - Collaborative Data Objects for NT Server - is a library which, as Microsoft puts it, "exposes messaging objects for use by Microsoft® Visual Basic® [and other programming languages]". Although CDONTS provides a number of objects with their properties and their methods, the CDONTS NewMail object is all that is required to email-enable ASP web pages. And using NewMail can be extremely easy. This page covers the NewMail object's properties and the methods that can be used to support HTML forms to create email. A couple of points of background may help in placing NewMail into your thinking about a practical application. The CDONTS library allows server applications to send and receive email without interacting with Microsoft Exchange Server or even needing access to Exchange. It communicates directly with the SMTP server available in IIS. Note, also, that the SMTP Server in IIS has its own message store in which the Inbox and Outbox are mapped to the file system. No other folders exist or are allowed to exist. This is different to CDONTS when used on an Exchange Server where each messaging user has their own Inbox. Applications created using CDONTS are interchangable between IIS and Exchange environments except where the NewMail object is used. So, what we are discussing below is applicable to web servers running IIS. CDONTS is designed to be used in a server environment: There is no user interface.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
This table shows all the properties of the NewMail object -Below the table follows more detail on the six key properties, To, From, Subject, Body, BodyFormat and MailFormat which, together with Send are what you need to use to send a message. In the descriptions below the code examples should be preceded by code which sets up the NewMail object, such as
The value assigned to the To property is one or more recipient addresses. Each should be a full messaging address such as
If there is more than a single recipient each messaging address must be seperated by a semicolon, as:
It's a straightforward string, so coda can assign the above recipients using:
The From property adds the sender's messaging address to the email. It's another string and can contain only one email address and cannot contain a semicolon.
The Subject property is the text that appears in the subject line of the message. Again, this is a simple string and can be set to null (zero length string; blank, that is, but bear in mind recipients may not appreciate having to open an email just to see what it's about) It can be set to a very long string but most users will only be ale to see the first part of a long string.
The body property allows you to add text to the main part of the email: It's body. C-languages and Java can use the IStream but, in VBScript, this is a string property. The message's body can contain a string of either plain text or HTML. The BodyFormat property must be set to one for plain text or reset to zero to allow HTML content. See BodyFormat, below. The text can be formatted with newline characters.
MailFormat allows you to select MIME encoding or plain text by using a number, as
Using a provided constant, the variable could be set up for MIME encoding by using the code
This property determines how the Attach and AttachURL methods work and this property is automatically set to zero (The value of CdoMailFormatMime) without any code to do this. Only set this to 1 if you are working in plain text. If BodyFormat is set to 1 it indicates that the body of the message is exclusively plain text. A value of zero indicates text which conatins - or may contain - HTML markup. The options here are, plain text only:
And for HTML encoded content:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The Send method brings together the properties described above to send a message through the SMTP server. As shown in the table above, most of the proprties are optional but a number are (quite logically!) necessary to properly send an email. Once all the proprties have been assigned values the message can be sent using simply
And finally . . . After all the processing is completed you should, properly, wrap up with
And further . . . There is masses on the Microsoft web site to fill in the gaps and further inform: at http://www.microsoft.com search for "CDONTS NewMail" or start out at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdo/html/_denali_newmail_object_cdonts_library_.asp |
xxx,xxx