<% Option Explicit '--------------------------------- ' Constant variables '--------------------------------- Const FileExt = ".txt" 'Const ValidEmailFolder = "/clients/javascript.nu/wwwroot/cgi4free/emailaddresses/validaddresses/" Const ValidEmailFolder = "\cgi4free\emailaddresses\validaddresses\" 'Unescaping \ is not necessary Const RedirectUrlWhenPostNotUsed = "http://www.javascript.nu/cgi4free/" Const ShowAds = True '--------------------------------- ' Form variables '--------------------------------- Dim MsgMsgSent Dim MsgInformationIsBelow Dim MsgClickToContinue Dim MsgSignUpCGI4Free Dim SendTo Dim SendCC Dim SendBCC Dim From Dim Subject Dim Priority Dim BodyFormat Dim MailFormat Dim Redirect Dim Language Dim CustomTextColor Dim CustomLinkColor Dim CustomVlinkColor Dim CustomBackgroundColor Dim CustomBody 'This will always be set and the value it gets depend on the "CustomXXX" variables above Dim InvalidAddress Dim IPAddress Dim CurrentTime Dim CurrentDate Dim ReservedFormFields Dim ColorHexCode SendTo = Request.Form("to") SendCC = Request.Form("cc") SendBCC = Request.Form("bcc") From = Request.Form("from") Subject = Request.Form("subject") Redirect = Request.Form("redirect") Language = LCase(Request.Form("language")) CustomTextColor = LCase(Request.Form("custom_textcolor")) CustomLinkColor = LCase(Request.Form("custom_linkcolor")) CustomVlinkColor = LCase(Request.Form("custom_vlinkcolor")) CustomBackgroundColor = LCase(Request.Form("custom_backgroundcolor")) IPAddress = Request.ServerVariables("REMOTE_HOST") CurrentTime = time() CurrentDate = date() Set ReservedFormFields=Server.CreateObject("Scripting.Dictionary") Set ColorHexCode=Server.CreateObject("Scripting.Dictionary") '--------------------------------- ' Set values to constant hash tables '--------------------------------- Sub SetValuesToConstantHashTables ReservedFormFields.Add "to","" ReservedFormFields.Add "cc","" ReservedFormFields.Add "bcc","" ReservedFormFields.Add "from","" ReservedFormFields.Add "subject","" ReservedFormFields.Add "type","" ReservedFormFields.Add "priority","" ReservedFormFields.Add "custom_textcolor","" ReservedFormFields.Add "custom_linkcolor","" ReservedFormFields.Add "custom_vlinkcolor","" ReservedFormFields.Add "custom_backgroundcolor","" ReservedFormFields.Add "redirect","" ReservedFormFields.Add "language","" ColorHexCode.Add "black","000000" ColorHexCode.Add "navy","000080" ColorHexCode.Add "darkblue","00008b" ColorHexCode.Add "mediumblue","0000cd" ColorHexCode.Add "blue","0000ff" ColorHexCode.Add "darkgreen","006400" ColorHexCode.Add "green","008000" ColorHexCode.Add "teal","008080" ColorHexCode.Add "darkcyan","008b8b" ColorHexCode.Add "deepskyblue","00bfbf" ColorHexCode.Add "darkturquoise","00ced1" ColorHexCode.Add "mediumspringgreen","00fa9a" ColorHexCode.Add "lime","00ff00" ColorHexCode.Add "springgreen","00ff7f" ColorHexCode.Add "aqua","00ffff" ColorHexCode.Add "cyan","00ffff" ColorHexCode.Add "midnightblue","191970" ColorHexCode.Add "dodgerblue","1e90ff" ColorHexCode.Add "lightseagreen","20b2aa" ColorHexCode.Add "forestgreen","228b22" ColorHexCode.Add "seagreen","2e8b57" ColorHexCode.Add "darkslategray","2f4f4f" ColorHexCode.Add "limegreen","32cd32" ColorHexCode.Add "mediumseagreen","3cb371" ColorHexCode.Add "turquoise","40e0d0" ColorHexCode.Add "royalblue","4169e1" ColorHexCode.Add "steelblue","4682b4" ColorHexCode.Add "darkslateblue","483d8b" ColorHexCode.Add "mediumturquoise","48d1cc" ColorHexCode.Add "indigo","4b0082" ColorHexCode.Add "darkolivegreen","556b2f" ColorHexCode.Add "cadetblue","5f9ea0" ColorHexCode.Add "cornflowerblue","6495ed" ColorHexCode.Add "mediumaquamarine","66cdaa" ColorHexCode.Add "dimgray","696969" ColorHexCode.Add "slateblue","6a5acd" ColorHexCode.Add "olivedrab","6b8e23" ColorHexCode.Add "slategray","708090" ColorHexCode.Add "lightslategray","778899" ColorHexCode.Add "mediumslateblue","7b68ee" ColorHexCode.Add "lawngreen","7cfc00" ColorHexCode.Add "chartreuse","7fff00" ColorHexCode.Add "aquamarine","7fffd4" ColorHexCode.Add "maroon","800000" ColorHexCode.Add "purple","800080" ColorHexCode.Add "olive","808000" ColorHexCode.Add "gray","808080" ColorHexCode.Add "skyblue","87ceeb" ColorHexCode.Add "lightskyblue","87cefa" ColorHexCode.Add "blueviolet","8a2be2" ColorHexCode.Add "darkred","8b0000" ColorHexCode.Add "darkmagenta","8b008b" ColorHexCode.Add "saddlebrown","8b4513" ColorHexCode.Add "darkseagreen","8fbc8f" ColorHexCode.Add "lightgreen","90ee90" ColorHexCode.Add "mediumpurple","9370db" ColorHexCode.Add "darkviolet","9400d3" ColorHexCode.Add "palegreen","98fb98" ColorHexCode.Add "darkorchid","9932cc" ColorHexCode.Add "yellowgreen","9acd32" ColorHexCode.Add "sienna","a0522d" ColorHexCode.Add "brown","a52a2a" ColorHexCode.Add "darkgray","a9a9a9" ColorHexCode.Add "lightblue","add8e6" ColorHexCode.Add "greenyellow","adff2f" ColorHexCode.Add "paleturquoise","afeeee" ColorHexCode.Add "lightsteelblue","b0c4de" ColorHexCode.Add "powderblue","b0e0e6" ColorHexCode.Add "firebrick","b22222" ColorHexCode.Add "darkgoldenrod","b8860b" ColorHexCode.Add "mediumorchid","ba55d3" ColorHexCode.Add "rosybrown","bc8f8f" ColorHexCode.Add "darkkhaki","bdb76b" ColorHexCode.Add "silver","c0c0c0" ColorHexCode.Add "mediumvioletred","c71585" ColorHexCode.Add "indianred","cd5c5c" ColorHexCode.Add "peru","cd853f" ColorHexCode.Add "chocolate","d2691e" ColorHexCode.Add "tan","d2b48c" ColorHexCode.Add "lightgray","d3d3d3" ColorHexCode.Add "thistle","d8bfd8" ColorHexCode.Add "orchid","da70d6" ColorHexCode.Add "goldenrod","daa520" ColorHexCode.Add "palevioletred","db7093" ColorHexCode.Add "crimson","dc143c" ColorHexCode.Add "gainsboro","dcdcdc" ColorHexCode.Add "plum","dda0dd" ColorHexCode.Add "burlywood","deb887" ColorHexCode.Add "lightcyan","e0ffff" ColorHexCode.Add "lavender","e6e6fa" ColorHexCode.Add "darksalmon","e9967a" ColorHexCode.Add "violet","ee82ee" ColorHexCode.Add "palegoldenrod","eee8aa" ColorHexCode.Add "lightcoral","f08080" ColorHexCode.Add "khaki","f0e68c" ColorHexCode.Add "aliceblue","f0f8ff" ColorHexCode.Add "honeydew","f0fff0" ColorHexCode.Add "azure","f0ffff" ColorHexCode.Add "sandybrown","f4a460" ColorHexCode.Add "wheat","f5deb3" ColorHexCode.Add "beige","f5f5dc" ColorHexCode.Add "whitesmoke","f5f5f5" ColorHexCode.Add "mintcream","f5fffa" ColorHexCode.Add "ghostwhite","f8f8ff" ColorHexCode.Add "salmon","fa8072" ColorHexCode.Add "antiquewhite","faebd7" ColorHexCode.Add "linen","faf0e6" ColorHexCode.Add "lightgoldenrodyellow","fafad2" ColorHexCode.Add "oldlace","fdf5e6" ColorHexCode.Add "red","ff0000" ColorHexCode.Add "fuchsia","ff00ff" ColorHexCode.Add "magenta","ff00ff" ColorHexCode.Add "deeppink","ff1493" ColorHexCode.Add "orangered","ff4500" ColorHexCode.Add "tomato","ff6347" ColorHexCode.Add "hotpink","ff69b4" ColorHexCode.Add "coral","ff7f50" ColorHexCode.Add "darkorange","ff8c00" ColorHexCode.Add "lightsalmon","ffa07a" ColorHexCode.Add "orange","ffa500" ColorHexCode.Add "lightpink","ffb6c1" ColorHexCode.Add "pink","ffc0cb" ColorHexCode.Add "gold","ffd700" ColorHexCode.Add "peachpuff","ffdab9" ColorHexCode.Add "navajowhite","ffdead" ColorHexCode.Add "moccasin","ffe4b5" ColorHexCode.Add "bisque","ffe4c4" ColorHexCode.Add "mistyrose","ffe4e1" ColorHexCode.Add "blanchedalmond","ffebcd" ColorHexCode.Add "papayawhip","ffefd5" ColorHexCode.Add "lavenderblush","fff0f5" ColorHexCode.Add "seashell","fff5ee" ColorHexCode.Add "cornsilk","fff8dc" ColorHexCode.Add "lemonchiffon","fffacd" ColorHexCode.Add "floralwhite","fffaf0" ColorHexCode.Add "snow","fffafa" ColorHexCode.Add "yellow","ffff00" ColorHexCode.Add "lightyellow","ffffe0" ColorHexCode.Add "ivory","fffff0" ColorHexCode.Add "white","ffffff" End Sub '----------------------------------------------- ' Set the variables that need to be converted '----------------------------------------------- Sub SetVariables 'Set mail priority '0:low; 1:medel; 2:high priority If LCase(Request.Form("priority")) = "high" Then Priority = "2" ElseIf LCase(Request.Form("priority")) = "low" Then Priority = "0" Else Priority = "1" End If 'Set mail type (text or HTML) 'BodyFormat: 1:plain text; 0:HTML format 'MailFormat: If this is 1 long lines will automatically line break. This MUST be 0 if we want be able to send mail in HTML-format (otherwise the tags will be shown as plain text) If LCase(Request.Form("type")) = "text" Then BodyFormat = "1" MailFormat = "0" ElseIf LCase(Request.Form("type")) = "text_shortlines" Then BodyFormat = "1" MailFormat = "1" Else BodyFormat = "0" MailFormat = "0" End If If Subject = "" Then Subject = "Cgi4Free Formmail" End If If Redirect = "" Then Redirect = "http://www.javascript.nu/cgi4free/formmail/thanks.shtml" End If If Language = "swedish" Then MsgMsgSent = "Meddelandet skickat!" MsgInformationIsBelow = "Nedan kan du se vilken information som skickats." MsgClickToContinue = "Tryck här för att ta dig vidare" MsgSignUpCGI4Free = "Registrera dig för ditt eget Formmail script." Else MsgMsgSent = "Message Sent!" MsgInformationIsBelow = "The information you have submitted is shown below." MsgClickToContinue = "Click here to continue" MsgSignUpCGI4Free = "Sign up for your own free Formmail script." End If 'All CustomXXX values have already been converted to lower case If ColorHexCode.Exists(CustomTextColor) = True Then CustomTextColor = ColorHexCode.Item(CustomTextColor) Else CustomTextColor = ColorHexCode.Item("black") End If If ColorHexCode.Exists(CustomLinkColor) = True Then CustomLinkColor = ColorHexCode.Item(CustomLinkColor) Else CustomLinkColor = ColorHexCode.Item("blue") End If If ColorHexCode.Exists(CustomVlinkColor) = True Then CustomVlinkColor = ColorHexCode.Item(CustomVlinkColor) Else CustomVlinkColor = ColorHexCode.Item("red") End If If ColorHexCode.Exists(CustomBackgroundColor) = True Then CustomBackgroundColor = ColorHexCode.Item(CustomBackgroundColor) Else CustomBackgroundColor = ColorHexCode.Item("white") End If If From = "" Then From = "noemail@noemail.com" End If CustomBody = "" End Sub '--------------------------------- ' Returns true iff Filename exist. '--------------------------------- Function FileExist(Filename) ' Create a filesystem object Dim FSO set FSO = server.createObject("Scripting.FileSystemObject") ' Map the logical path to the physical system path Dim Filepath Filepath = Server.MapPath(Filename) 'Basically adds "d:\clients\javascript.nu\wwwroot" to the path FileExist = FSO.FileExists(Filepath) Set FSO = nothing End Function '--------------------------------- ' "abc@def.com" ==> "abc_a_def.com.txt" '--------------------------------- Function GetEmailWithFileNameFormat(Email) GetEmailWithFileNameFormat = Replace(Email, "@", "_a_") & FileExt End Function '----------------------------------------------- ' Exit execution if too much data is being sent. '----------------------------------------------- Sub ExitIfTooMuchDataIsBeingSent If Request.TotalBytes > 1000000 Then 'If the user tries to send more than 1 mb of data, then terminate execution Response.Write "Too much data is being sent." Response.Write "
" Response.Write "Please reduce the amount of text you try to send." Response.End End If End Sub '----------------------------------------------- ' Returns true iff email is valid (empty email is also valid) '----------------------------------------------- Function EmailIsValid(Email) EmailIsValid = (Email = "") OR FileExist(ValidEmailFolder & GetEmailWithFileNameFormat(Email)) End Function '----------------------------------------------- ' Returns true iff email is has a valid email format (like "abc@def.com") (empty email is also valid) '----------------------------------------------- Function EmailFormatIsValid(Email) Dim RegularExpressionObject Set RegularExpressionObject = New RegExp With RegularExpressionObject .Pattern = "^[^ ,;\@]+\@[^ ,;\@]+\.[a-zA-Z]{2,4}$" .IgnoreCase = True .Global = True End With EmailFormatIsValid = (Email = "") OR RegularExpressionObject.Test(Email) End Function '----------------------------------------------- ' Returns true iff to, cc and bcc are all valid email addresses. ' This also makes sure we do not enter more than one address per row. '----------------------------------------------- Function AllAddressesAreValid() InvalidAddress = "" If (Not EmailIsValid(SendTo)) Or (Not EmailFormatIsValid(SendTo)) Or SendTo = "" Then InvalidAddress = SendTo AllAddressesAreValid = False ElseIf Not EmailIsValid(SendCC) Or (Not EmailFormatIsValid(SendCC)) Then InvalidAddress = SendCC AllAddressesAreValid = False ElseIf Not EmailIsValid(SendBCC) Or (Not EmailFormatIsValid(SendBCC)) Then InvalidAddress = SendBCC AllAddressesAreValid = False Else AllAddressesAreValid = True End If End Function '----------------------------------------------- ' Returns true iff atleast one field with data has been sent with METHOD=post '----------------------------------------------- Function DataSentWithPost() If Request.Form.Count = 0 Then DataSentWithPost = False Else DataSentWithPost = True End If End Function '----------------------------------------------- ' Stuff to do or show if data is sent with POST '----------------------------------------------- Sub ShowDataSentWithPost() Response.Redirect RedirectUrlWhenPostNotUsed End Sub '----------------------------------------------- ' Send the actual email '----------------------------------------------- Sub SendEmail Dim fname, lname Dim objCDO 'Here is where we insert new code to invoke CDONTS 'This line invokes the object using the name objCDO ' Set objCDO = Server.CreateObject("CDONTS.NewMail") Set objCDO = Server.CreateObject("CDO.Message") ' Content-Type only for CDONTS ' objCDO.Value("Content-Type") = "text/html; charset=ISO-8859-1" objCDO.From = From objCDO.To = SendTo objCDO.Cc = SendCC objCDO.Bcc = SendBCC objCDO.Subject = Subject Dim Body Body = "" If BodyFormat = "1" Then 'if ($type eq "text") Body = Body & ( "This mail was sent to you by " & From & " (" & IPAddress & ") " & vbCrLf & _ "Sent on " & CurrentTime & " CET " & CurrentDate & vbCrLf & _ "--------------------------------------" & vbCrLf & vbCrLf) Else Body = Body & ( "" & vbCrLf & _ "" & vbCrLf & _ "" & Subject & "" & vbCrLf & _ "" & vbCrLf & _ "" & vbCrLf & _ "" & vbCrLf & _ "
" & vbCrLf & _ "" & vbCrLf & _ "" & vbCrLf & _ "" & vbCrLf) End If Dim FieldName Dim FieldNameLowerCase Dim FieldValue Dim i for i=1 to Request.Form.Count FieldName = Request.Form.Key(i) FieldNameLowerCase = LCase(FieldName) If ReservedFormFields.Exists(FieldNameLowerCase) = False Then FieldValue = Request.Form(FieldName) If BodyFormat = "1" Then 'if ($type eq "text") Body = Body & FieldName & " = " & FieldValue & vbCrLf & vbCrLf Else FieldValue = Replace(FieldValue,"<","<") FieldValue = Replace(FieldValue,">",">") FieldValue = Replace(FieldValue,vbCrLf,"
") Body = Body & ( "" & vbCrLf & _ "" & vbCrLf & _ "" & vbCrLf) End If End If Next If BodyFormat = "1" Then 'if ($type eq "text") Body = Body & (vbCrLf & vbCrLf & _ "--------------------------------------" & vbCrLf & _ "Sign up for your own free formmail at:" & vbCrLf & _ "http://www.javascript.nu/cgi4free/" & vbCrLf) Else Body = Body & ( "" & vbCrLf & _ "" & vbCrLf & _ "
This mail was sent to you by " & From & " (" & IPAddress & ")
Sent on " & CurrentTime & " CET " & CurrentDate & "
" & FieldName & "
" & FieldValue & "
 
Sign up for your own free formmail
" & vbCrLf & _ "") End If If BodyFormat = "1" Then objCDO.TextBody = Body Else objCDO.HtmlBody = Body End If ' objCDO.BodyFormat = BodyFormat ' objCDO.MailFormat = MailFormat objCDO.Send Set objCDO = Nothing End Sub '----------------------------------------------- ' Output display functions '----------------------------------------------- Sub ShowEmailsAreNotValid() Response.Write "Email address " & InvalidAddress & " not allowed" Response.Write CustomBody Response.Write "
" Response.Write "" If SendTo <> "" Then Response.Write "You are not allowed to send an email to " & InvalidAddress & ". " Response.Write "

" Response.Write "However, if " & InvalidAddress & " is your e-mail you can sign up for a free Cgi4Free account and start sending mail to " & InvalidAddress & " using this form. " Response.Write "
" Response.Write "If you are already a Cgi4Free member, just login and agree to the Formmail License before you use this service. " Response.Write "You must first login and then visit this link: " Response.Write "
" Response.Write "Add " & InvalidAddress & " to the database with e-mail addresses that are allowed to use this formmail script" Response.Write "

" Response.Write "
" Response.Write "Sign up for your FREE Cgi4Free account!" Else Response.Write "Please specify where the mail shall be sent.
" Response.Write "Example:
" Response.Write "<INPUT TYPE=""hidden"" NAME=""to"" VALUE=""your@email.com"">" End If Response.Write "
" Response.Write "

" Response.Write "" End Sub Sub ShowMessageSent() %> <%=MsgMsgSent%> <%=CustomBody%>
<% If ShowAds Then %> <% End If %>

<%=MsgMsgSent%>

<%=MsgInformationIsBelow%>
<%=MsgClickToContinue%>


<% Dim FieldName Dim FieldNameLowerCase Dim FieldValue Dim i for i=1 to Request.Form.Count FieldName = Request.Form.Key(i) FieldNameLowerCase = LCase(FieldName) If ReservedFormFields.Exists(FieldNameLowerCase) = False Then FieldValue = Request.Form(FieldName) FieldValue = Replace(FieldValue,"<","<") FieldValue = Replace(FieldValue,">",">") FieldValue = Replace(FieldValue,vbCrLf,"
") Response.Write "" & FieldName & "
" & FieldValue Response.Write "

" End If Next %>


<%=MsgSignUpCGI4Free%>
<% ' Response.Redirect Redirect End Sub '----------------------------------------------- ' Actual program execution '----------------------------------------------- ExitIfTooMuchDataIsBeingSent() 'Don't allow too much data to be sent, to prevent abuse SetValuesToConstantHashTables() 'Sets for example the hash table mapping "white" => "FFFFFF" If Not DataSentWithPost() Then ShowDataSentWithPost() ElseIf AllAddressesAreValid() Then SetVariables() SendEmail() ShowMessageSent() Else ShowEmailsAreNotValid() End If Response.End %>