An application page with the CFMAIL tag dynamically generates email messages based on the tag's settings. Some of the things you can accomplish with CFMAIL are:
In the example below, the contents of a customer inquiry form submittal are forwarded to the marketing department. Note that the same application page could also insert the customer inquiry into the database.
<CFMAIL FROM="#Form.EMailAddress#" TO="marketing@allaire.com" SUBJECT="Customer Inquiry"> A customer inquiry was posted to our Web site: Name: #Form.FirstName# #Form.LastName# Subject: #Form.Subject# #Form.InquiryText# </CFMAIL>
In the example below, a query ("ProductRequests") is run to retrieve a list of the customers who have inquired about a product over the last seven days. This list is then sent, with an appropriate header and footer, to the marketing department:
<CFMAIL QUERY="ProductRequests" FROM="webmaster@allaire.com" TO="marketing@allaire.com" SUBJECT="ColdFusion status report"> Here is a list of people who have inquired about Allaire ColdFusion over the last seven days: <CFOUTPUT> #ProductRequests.FirstName# #ProductRequests.LastName# (#ProductRequests.Company#) - #ProductRequests.EMailAddress# </CFOUTPUT> Regards, The WebMaster webmaster@allaire.com </CFMAIL>
Note the use of the nested CFOUTPUT tag to present a dynamic list embedded within a normal CFMAIL message. The text within the CFOUTPUT is repeated for each row in the "ProductRequests" query, while the text above and below it serve as the header and footer (respectively) for the mail message.
In the following example, a query ("CFBetaTesters") is run to retrieve a list of people who are beta testing ColdFusion. This query is then used to send a notification to each of these testers that a new version of the beta release is available:
<CFMAIL QUERY="CFBetaTesters" FROM="beta@allaire.com" TO="#TesterEMail#" SUBJECT="ColdFusion Beta Four Available"> To all ColdFusion beta testers: ColdFusion Beta Four is now available for downloading from the Allaire site. The URL for the download is: http://beta.allaire.com Regards, ColdFusion Technical Support beta@allaire.com </CFMAIL>
Note that in this example, the contents of the CFMAIL tag are not dynamic, that is, they don't use any # delimited dynamic parameters. What is dynamic is the list of email addresses to which the message is sent. Note the use of the "TesterEMail" column from the "CFBetaTesters" query in the TO attribute.