Welcome!

ColdFusion Authors: Maureen O'Gara, Hovhannes Avoyan, Yakov Fain, Pat Romanski, Liz McMillan

Related Topics: ColdFusion

ColdFusion: Article

Using Gateways PART 2

The basics

The two other members, the sender address and the subject line, are added to the structure. Finally, on line 15, the EmailBlaster gateway instance is invoked with a call to sendGatewayMessage and the message structure is passed.

The Change Up
Clearly there is a problem in making EmailBlaster useful in any capacity if it's only capable of calling to a single listener CFC. It would be imminently more useful if additional data elements could be passed and different e-mail letter content could be used. One way of doing this, which serendipitously helps to demonstrate a cool feature of gateways, is to indicate a different listener CFC in the messageStruct passed to sendGatewayMessage.

The Calling Logic, Part Deux
A few additions to what was our original calling logic will produce Newsletter.cfm (see Listing 3).

Herein there are two additional columns added to the query that is being sent in the messageStruct, firstname, and lastname. Everything else remains more or less the same until line 15 where the structure member cfcPath (which was shown briefly in Table 3) is added, indicating the Newsletter.cfc in the same calling directory (obtained using CFML's expandPath function).

The Listener CFC, Part Deux
The new listener CFC, Newsletter.cfc (see Listing 4), is merely a rehash of the default listener configured in the ColdFusion Administrator for this gateway instance. The one point of change is line 10 where the two new columns added in the calling logic are pasted into the output of the e-mail body.

It should be noted that the sample code for this article requires that you do two things before you can successfully run the examples:

1.  Configure your ColdFusion Server's mail server settings

2.  Change the e-mail addresses used in the templates to valid values:

  • EmailBlaster.cfm, line 7
  • EmailBlaster.cfm, line 10
  • Newsletter, line 9
  • Newsletter, 12
Wrapping It Up
The simple examples in this article demonstrate only the barest minimum of a more complicated system. Now that you have a basic grounding in setting up gateway instances, writing listener CFCs, and passing messages to instances, we can dig a little bit deeper. The next installment in this series will look at integrating gateway instance into applications using ColdFusion's persistent scopes and what some of the impacts upon some popular practices.

Be sure to drop by the CCOJ blog and post your feedback and questions about this article and the series. (Note: Listings 1-4 are also available on the CCOJ blog [http://ccoj.coldfusionjournal.com], ccojas-part2-code.zip.)

More Stories By Guy Rish

Guy Rish is a ColdFusion and .NET developer at Vente as well as President at Gestaltech. He is an active developer and writer for various languages and technologies, and has contributed work in books on ColdFusion MX, Flash MX, and Dreamweaver MX. He blogs at ccoj.coldfusionjournal.com.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.