Search This Blog

Tuesday, July 05, 2011

ColdFusion: Quick email test page

I have to occasionally look at email on a ColdFusion server. I wanted a way to quickly test email addresses so I built the following page.

It allows To, From, Subject, Message and the SMTP server address to be manipulated. It is one page as it posts to itself. The code is very much hacked to together as I just want this as a test page and I had to create it quickly. You should be able to easily modify it to add additional features.

email.cfm

<html> 
<head> 
    <title>CFM Email</title> 
</head> 
<body>
    
<cfparam name="Form.Message" default="">
<cfparam name="Form.To" default="">
<cfparam name="Form.Subject" default="">
<cfparam name="Form.From" default="">
<cfparam name="Form.SMTPServer" default="">
<cfif Form.SMTPServer is not "" and Form.To is not "" and Form.From is not "">
<CFMAIL
    server="#Form.SMTPServer#"
    TO="#Form.To#" 
    FROM= "#Form.From#"
    SUBJECT= "#Form.Subject#"
>
#Form.Message#
</CFMAIL> 
Email sending is being attempted using <br/>
<CFOUTPUT> 
SERVER: #Form.SMTPServer#<br/>
TO: #Form.To#<br/>
FROM: #Form.From#<br/>
SUBJECT: #Form.Subject#<br/>
MESSAGE: #Form.Message#<br/>
</CFOUTPUT>
<cfelse>
Email sending not attempted as parameters currently incorrect please change<br/>
To, From and Server must be filled in.<br/>
</cfif>
<CFFORM METHOD="POST" action="email.cfm"> 
<table border="1" cellpadding="0" cellspacing="0" width="750" bordercolor="#000000"> 
<tr> 
<td width="250"><b><i>To:</i></b></td>
<td width="500"><input type="text" name="To" size="100" Required="Yes" "Please enter to email address." value="<cfoutput>#Form.To#</cfoutput>"></td> 
</tr>  
<tr> 
<td width="250"><b><i>From:</i></b></td> 
<td width="500"> <input type="text" name="From" size="100" Required="Yes" Message="Please enter from email address." value="<cfoutput>#Form.From#</cfoutput>"> 
</td> 
</tr> 
<tr> 
<td width="250"><b><i>SMTP Server:</i></b></td> 
<td width="500"> <input type="text" name="SMTPServer" size="100" Required="Yes" Message="Please enter from SMTP Server URL or IP." value="<cfoutput>#Form.SMTPServer#</cfoutput>"> 
</td> 
</tr>
<tr> 
<td width="250"><b><i>Subject</i></b></td> 
<td width="500"><input type="text" name="Subject" size="100" REQUIRED="YES" MESSAGE="Subject" value="<cfoutput>#Form.Subject#</cfoutput>"> 
</td> 
</tr>  
<tr> 
<td width="250"><b><i>Message</i></b></td> 
<td width="500"> 
<p><textarea rows="10" name="Message" cols="77"><cfoutput>#Form.Message#</cfoutput></textarea> 
</table> 
<br> 
<input type="submit" value="Submit"><input type="reset" value="Reset"></p> 
</cfform> 
</body> 
</html>

Share/Bookmark

No comments:

Post a Comment