The CDONTS NewMailObject

The Microsoft CDO for NTS Library version 1.2 exposes messaging objects for use by Visual Basic, C/C++, Visual C++, and VBScript applications. The library makes it easy to add mail functionality (both sending and receiving) into the server-side of your Visual InterDev 6.0 applications via ASP scripting. There is no user interface supported by the library, and you must be running on Windows NT 4.0. The nice thing about the CDONTS Library is that you don't even need to be running Exchange—all you need is the SMTP server component of IIS 4.0 installed.

The NewMail object is just one object in the CDONTS Library. Other objects are shown in Table 17-12.

Table 17-12. Objects in the CDONTS Library.

Object Description
AddressEntry Specifies addressing information for an individual messaging user
Attachment Associates an additional object with a message
Attachments collection Accesses all attachments on a message; creates new attachments
Folder Opens the default Inbox or Outbox folder in a message store
Message Composes, populates, sends, and receives an e-mail document
Messages collection Accesses all messages in a folder; creates new messages
Recipient Specifies information for a messaging user intended to receive a message
Recipients collection Accesses all recipients of a message; creates new recipients
Session Establishes a connection between an application and a messaging system

The NewMail object is specifically designed to give developers a quick way to send an automated message with little coding required. All that's needed is to create the object, set some properties, send the message, and then set the object to Nothing to clean up. You can even send file attachments or send attachments with an associated URL.

The following code shows an example of how to create the NewMail object and then send an e-mail message:

 <@ Language=VBScript %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> </HEAD> <BODY> <OBJECT RUNAT=server PROGID=CDONTS.NewMail id=oNewMail></OBJECT> <% oNewMail.From = "nick.evans@us.pwcglobal.com" oNewMail.To = "nick.evans@us.pwcglobal.com" oNewMail.Subject = "CDONTS" oNewMail.Body = "This NewMail object makes sending e-mail simple!" oNewMail.Send Set oNewMail = Nothing %> </BODY> </HTML> 

The code below shows an example of how to create the NewMail object and then send a file attachment within an e-mail message:

<OBJECT RUNAT=server PROGID=CDONTS.NewMail id=objNewMail> </OBJECT> objNewMail.AttachFile("\\ntserver\reports\1998q1.xls", "1998Q1.XLS") objNewMail.Send("Automated Report Generator", "manager@xyz.com", _     "1998 Sales Report _ 1st Quarter", _     "Here's the latest sales report for the 1st quarter 1998", 0) objNewMail = Nothing 

In this code example, the parameters included within the Send method specify the sender, recipient, subject line, body, and importance of the e-mail message, as the following syntax shows:

ObjNewMail.Send ( [From] [, To] [, Subject] [, Body] [, Importance] ) 

These parameters correspond to the From, To, Subject, Body, and Importance properties of the NewMail object. The AttachFile method takes the full path and filename of the file plus the file name to appear in the attachment's placeholder in the message as arguments.

In your applications, you could easily create an HTML form to capture user input in a feedback form and then pass those values as the parameters for the e-mail message. This is a great way to automate the capture of input and the creation and routing of e-mail messages. In addition to forwarding the e-mail messages to the appropriate parties (perhaps based upon a selection from a drop-down list), you can also store the e-mail responses in a relational database. This way you have both a workflow process—so that the e-mails get routed—and a storage area for the e-mail information for analysis at a later date. For example, in an Internet Banking application you might have a loan application form for your users to complete. The message body in the completed form could be e-mailed to the loan processing department and the rest of the data could be captured in a relational database table so that the loan processors can access it later on. The CDONTS Library extends the possibilities for your Visual InterDev applications so that you can move from relational database access into the world of e-mail and workflow.



Programming Microsoft Visual InterDev 6. 0
Programming Microsoft Visual InterDev 6.0
ISBN: 1572318147
EAN: 2147483647
Year: 2005
Pages: 143

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net