http://www.chrispearson.org/pages/programming/vbscript/Email/ASPEmail.asp
09h16
Wednesday, 8. October 2008

GENERATING EMAIL

Using code to create email messages can be very useful - Not just a way of generating spam!


Generally, email is pretty reliable and relatively secure, so transferring blocks of data between systems (between users or just between systems) can benefit from the use of email. (By pretty reliable and relatively secure I mean as compared with other, virtually free-to-use and low-cost options.)

Email messages can be used to communicate

  • user to user
      usually manually-created message text
  • machine to user
      bulk mailings
      notifications to signed-up recipients
      spam
  • user to machine
      responses to machine-to-user messages
      manually-created submissions to automated services
  • machine to machine
      machine readable messages
         messages in pre-agreed formats
      
      XML-parsable message content

I've been involved in a number of projects that have used the Windows MAPI or the Outlook object to create mail messages in a pre-defined format, email as the transport mechanism and MAPI to receive the message.

Back in the early- to mid-ninetees this technology allowed you to create applications that used mail networking to connect systems that were otherwise isolated in their own LANs (Local area networks)

The CDONTS available on IIS makes email collaboration much easier. The availability of XML parsers now makes breaking out a message's data much easier, too.

CDONTS
What is it?
 

What uses does automated email have?

There are all kinds of scenarios - some more contrived than others.

A couple of genuinely useful applications I've worked on are

Error messaging - Posting to a web site

A server-based application creates documents which are posted to a remote web site.

This uses FormScape to create a document set which is FTPed to a web site, from a server on the LAN to a web server beyond the firewall. Once the FTP Put is completed the application attempts a FTP Get. If the Get is successful, the availability of the file set on the web server is confirmed.

If the retrieve operation fails an email is sent to the responsible person, warning them of a probable posting failure. A corrective process is then initiated.

Standard messages - Delivery advice

An application which posts despatch documents onto a web site also generates a despatch confirmation message which is emailed to the customer

 

CDONTS is a COM technology - collaboration data object for NT server is where the acronym comes from. The CDONTS NewMail object exposes email properties which you can set in code. It has methods which can be used to do things with the object, like sending a mail message.

While this article probably provides sufficient information to create an ASP page that uses the CDONTS NewMail object, there is more extensive information available at the Microsoft web site: Visit http://msdn.microsoft.com/library/default.asp for Introduction to CDO for NTS and onward links.

Watch out!

The CDONTS NewMail object talks directly to a SMTP service running on a web server. So to test an application (an ASP web page, for instance) you need access, typically, to a web server running IIS with SMTP configured (most IIS implementations do) and CDO services running (again, likely but do check!). You can't do local testing using personal web server - Microsoft PWS doesn't support these services.

Fortunately, since the code needed to drive the CDONTS NewMail object is fairly straightforward, testing needn't be an issue.

Get all the other ASP on the page tested and working before switching in the email code. Then upload and trial the page.

    Properties and methods:
A summary of CDO for NT server
 
The NewMail object
Summary
Properties
Methods
  Object Properties Methods
  AddressEntry Address, Application, Class, Name, Parent, Session, Type None
  Attachment Application, Class, ContentBase, ContentID, ContentLocation, Name, Parent, Session, Source, Type Delete, ReadFromFile, WriteToFile
  Attachments collection Application, Class, Count, Item, Parent, Session Add, Delete
A sample project
A demonstration using the NewMail object and the
code used in its ASP scripting
  Folder Application, Class, Messages, Name, Parent, Session None
  Message Application, Attachments, Class, ContentBase, ContentID, ContentLocation, HTMLText, Importance, MessageFormat, Parent, Recipients, Sender, Session, Size, Subject, Text, TimeReceived, TimeSent Delete, Send
  Messages Application, Class, Count, Item, Parent, Session Add, Delete, GetFirst, GetLast, GetNext, GetPrevious
NewMail Bcc, Body, BodyFormat, Cc, ContentBase, ContentLocation, From, Importance, MailFormat, Subject, To, Value, AttachFile, AttachURL, Send, SetLocaleIDs
Recipient Address, Application, Class, Name, Parent, Session, Type Delete
Recipients collection Application, Class, Count, Item, Parent, Session Add, Delete
Session Application, Class, Inbox, MessageFormat, Name, Outbox, Parent, Session, Version GetDefaultFolder, Logoff, LogonSMTP, SetLocaleIDs
 
 

xxx,xxx

copyright ©2000 - 2008 Chris Pearson