Here is a web based email script if anyone needs it. It performs basic validation and smtp authentication. I have not tested it with AOL yet but it works perfectly otherwise. I have changed the script per skypanthers comments below. This is just an example that runs “Out of the box”.
http://www.actionwebhosts.com/images/sample.gif
<%@ Language=VBScript %>
<%
dim site_url,referer
dim validPost
dim vName,vEmail
dim sName,sEmail,sSubject,sMessage
dim validReferer
dim errText
dim iMsg,iConf,Flds,MailServer,UserEmail,UserPass
'get data from form
sName = Trim(Request.Form(“Name”))
sEmail = Trim(Request.Form(“Email”))
sSubject = Trim(Request.Form(“Subject”))
sMessage = Trim(Request.Form(“Message”))
'basic email validation
function isValidEmail(byval sEmail)
’ very simple email validation function.
returnVal = false
if not isEmpty(sEmail) then
if instr(sEmail, “@”) > 0 and instr(sEmail, “.”) > 0 then
returnVal = true
end if
end if
isValidEmail = returnVal
end function
’ validate required fields
if sName = “” then vName=false else vName=true end if
if not isValidEmail(sEmail) then vEmail=false else vEmail=true end if
validPost = (vName and vEmail)
’ if form has not yet been submitted, set initial form state
if Trim(Request.Form(“isSubmitted”)) = “” then
vName=true
vEmail=true
vSubject=true
vMessage=true
end if
if validPost then ’ all fields are valid
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'SCRIPT CONFIGURATION
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
’
site_url = “yourdomain.com” 'DOMAIN where this form will reside ! DO NOT INCLUDE http://www .
page_url = “yourform.asp” 'PAGE URL (Example: form.asp)
MailServer = “mail.yourdomain.com” 'SMTP MAIL SERVER
UserEmail = “[email protected]” 'EMAIL ADDRESS for the form results (recipient)
UserPass = “password” 'PASSWORD for the POP/SMTP UserEmail account
’
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'END CONFIGURATION
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'check HTTP_REFERER
referer = Request.ServerVariables(“HTTP_REFERER”)
’ not validReferer
if InStr(1,referer,site_url,0) = 0 then
validReferer = false
errText = “
E R R O R !
As a security measure, this form will not work when accessed from outside of the “” & site_url & “” domain. If you feel you have reached this page in error, please
click here to try again.
”
else
’ validReferer
validReferer = true
'SEND EMAIL using CDOSYS mail object Windows 2000+
set iMsg = Server.CreateObject(“CDO.Message”)
set iConf = Server.CreateObject (“CDO.Configuration”)
'set and update fields properties
Set Flds = iConf.Fields
'SMTP server
Flds(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = MailServer
'SMTP port
Flds(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25
'CDO Port
Flds(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2
'timeout
Flds(“http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout”) = 60
'outgoing authentication
Flds(“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”) = 1 'basic (clear-text) authentication
Flds(“http://schemas.microsoft.com/cdo/configuration/smtpusessl”) = False 'Use SSL for the connection (True or False)
Flds(“http://schemas.microsoft.com/cdo/configuration/sendusername”) = UserEmail
Flds(“http://schemas.microsoft.com/cdo/configuration/sendpassword”) = UserPass
Flds.Update
Set iMsg.Configuration = iConf
iMsg.From = sName & " <" & sEmail & “>”
iMsg.Subject = sSubject
iMsg.To = UserEmail
'iMsg.HTMLBody = “”
iMsg.TextBody = “” & vbCrLf _
& "The following was submitted on " & FormatDateTime(Now(),1) & “:” & vbCrLf _
& vbCrLf _
& "Name: " & sName & vbCrLf _
& "Email: " & sEmail & vbCrLf _
& vbCrLf _
& "Message: " & vbCrLf _
& “------------------” & vbCrLf _
& sMessage & vbCrLf _
& vbCrLf _
& vbCrLf _
‘’ send the mail
on error goto 0
iMsg.Send
'close resources
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
end if ’ end HTTP_REFERER check
else ’ validPost
’ re-display the form with values pre-filled
’ and problem fields highlighted
end if ’ validPost
%>
Sample Form to Validate and Authenticate SMTP Email
">
| Sample Form to Email Using CDOSYS |
with SMTP Authentication |
|
<% If validPost and validReferer Then ’ display success message %>
Success!
<a href=“<%Response.Write request.ServerVariables(“SCRIPT_NAME”)%>” class=“style2 style18”>[
back to sample form]
<% ElseIf validPost and validReferer=false Then %>
Email Not Sent!
<% 'End If 'not validReferer %>
<% Else %>
<% if Trim(Request.Form(“isSubmitted”)) = “yes” then 'is submiited? %>
E R R O R ! : The shaded fields below are required:
<% Else %>
Includes some basic validation and a site referrer check.
<% End If ’ is submitted? %>
<% End If 'validPost %>
|
| Name: |
" size="30"<%if not vName then%> class="errorItem"<% End If %>> |
| Email: |
" size="30" maxlength="50"<%if not vEmail then%> class="errorItem"<% End If %>> |
| Subject: |
" size="60"> |
| Message: |
<%Response.Write request.form("Message")%> |
| |
|
|
|
|