In this chapter, you are going to begin the process of looking at how ColdFusion can be used to interact with various Internet protocols including e-mail, File Transfer Protocol (FTP), and the World Wide WeQ.
In this chapter we will start with a discussion of the Simple Mail Transfer Protocol (SMTP), which can be used by ColdFusion for sending e-mail messages on a local intranet or Internet. First, you will learn how to configure C-qtdFusion to use your SMTP server for sending e-mail. Then, you will learn about the CFMAIl tag, which is the key to sending e-mail from ColdFusion.
Preparing ColdFusi n to Send E-Mail
To prepare to send e-mail with ColdFusion, you first need to tell ColdFusion where it can find your SMTP server. To do this, you will need to identify the host name or numerical IP address of your mail server.
If you aren’t sure of where to find this information, the following guidelines can help:
• If you are developing your Web site on a corporate intranet, then your organization probably already has an internal mail server running that supports SMTP. Consult your network administrator to determine the host name or address of the SMrP server for your intranet. Some organizations may have mail systems that do not support SMTP. In this case, you will need to arrange with your network administrator· to install the necessary software so that your corporate e-mail system supports SMTP.
• If you are developing your Web’site for the Internet and your organization has a leased line to the Internet, then your organization probably has an SMTP server that is used for receiving and sending e-mail to and from the Internet. In this case, your network administrator can provide you with the host. name of the server.
• If you are developing your Web site for the Internet and the site will be hosted at your Internet Service Provider’s location, then you will want to use your ISP’s . SMTP server for sending e-mail. Consult your ISP’s support staff to determine the host name of the appropriate server.
With this information in hand, you need to open the ColdFusion AdministratorWeb’ page and select the Mail tab to configure the SMTP server. As you can the mail configuration screen of the ColdFusion Administrator is quite Simple. It contains only three fields:
Mail Server The host flame or IP addfess of your SMTP server.
Server Port The TCP lIP port used to connect to the server. The default value of 25 is the correct port for the vast majority of SMTP servers, especially those connected to the Internet. Only in special cases should you change this number: your network administrator or ISP can tell you if a nonstandard port is being used. Connection Timeout This field specifies the number of seconds ColdFusion should wait before giving up when attempting to connect to the SMTP server. With a reliable connection to your mail server, the default value of 60 seconds should be fine. If your mail server is not reliable and you find that your connections frequently time out, try increase this value to 120 seconds or even more.
After you have entered the necessary values (at the very least, you need to provide the Mail Server value even if you don t want to change the other two values from their defaults), click the Apply button. The screen will redraw with the correct values filled.
After you have committed your changes with the Apply button, you should test your mail server connection by using the Verify button. This will cause Cold Fusion to check whether it can connect to your SMTP ~rver with the port setting you have specified. If the connection is successful, Coldfusion will inform you with the screen Otherwise, you will see an error screen with a brietdescription of the problem. Common errors include:
Name of host cannot be resolved to address You have probably typed the host name incorrectly. Double-check the ho~t name and try again.
Remote host is not available (check host part of address) ColdFusion has failed to connect to the server you have specified. Possible causes include an incorrect IP address for the server, a connection timeout value that is too short, or physical prolems with the SMTP server itself (it could be off or disconnected from the network, for instance).