Solved

Formmail.ASP won't work on new Webserver

Posted on 2006-07-07
25
835 Views
Last Modified: 2007-12-19
Hey guys,

We have a webform that compiles data into an email and sends it to a recipient at our domain. We changed email servers and webservers to inhouse. However, I can't yet get the same exact webpage to work on our new server.

here is the webbpage please view the source..it's supposed to use the formmail.asp file to compile the email and send. However, it wont work on our new server. Our new email server uses ArgoSoft Mail Pro (latest build), the website is hosted on IIS 6.0. Maybe I'm missing a component??

webpage http://smtp.indyice.com/workorder


***********************************FORMMAIL.ASP CODE***************************

9:14 AM 7/7/2006<html>



<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<meta name="GENERATOR" content="Microsoft FrontPage 5.0">

<meta name="ProgId" content="FrontPage.Editor.Document">

<title>Indyice Workorder</title>

<style TYPE ="text/css">

<!--

                              A:hover {color:"#FF3300";}

-->

</style>

</head>

<body>

<%@ LANGUAGE="VBScript" %>
<% '***************************************************************************
   '* ASP FormMail                                                            *
   '*                                                                         *
   '* Do not remove this notice.                                              *
   '*                                                                         *
   '* Copyright 1999-2002 by Mike Hall.                                       *
   '* Please see http://www.brainjar.com for documentation and terms of use.  *
   '***************************************************************************

   '- Customization of these values is required, see documentation. -----------

   referers   = Array("indyice.com", "www.indyice.com", "smtp.indyice.com")
   mailComp   = "CDONTS"
   smtpServer = "smtp.indyice.com"
   fromAddr   = "workorders@indyice.com"
   toAddr     = "ohlookitstoppedsnowing@gmail.com"

   '- End required customization section. -------------------------------------

   Response.Buffer = true
   errorMsgs = Array()

   'Check for form data.

   if Request.ServerVariables("Content_Length") = 0 then
     call AddErrorMsg("No form data submitted.")
   end if

   'Check if referer is allowed.

   if UBound(referers) >= 0 then
     validReferer = false
     referer = GetHost(Request.ServerVariables("HTTP_REFERER"))
     for each host in referers
       if host = referer then
         validReferer = true
       end if
     next
     if not validReferer then
       if referer = "" then
         call AddErrorMsg("No referer.")
       else
         call AddErrorMsg("Invalid referer: '" & referer & "'.")
       end if
     end if
   end if

   'Check for the recipients field.

   if Request.Form("_recipients") = "" then
     call AddErrorMsg("Missing email recipient.")
   end if

   'Check all recipient email addresses.

   recipients = Split(Request.Form("_recipients"), ",")
   for each name in recipients
     name = Trim(name)
     if not IsValidEmailAddress(name) then
       call AddErrorMsg("Invalid email address in recipient list: " & name & ".")
     end if
   next
   recipients = Join(recipients, ",")

   'Get replyTo email address from specified field, if given, and check it.

   name = Trim(Request.Form("_replyToField"))
   if name <> "" then
     replyTo = Request.Form(name)
   else
     replyTo = Request.Form("_replyTo")
   end if
   if replyTo <> "" then
     if not IsValidEmailAddress(replyTo) then
       call AddErrorMsg("Invalid email address in reply-to field: " & replyTo & ".")
     end if
   end if

   'Get subject text.

   subject = Request.Form("_subject")

   'If required fields are specified, check for them.

   if Request.Form("_requiredFields") <> "" then
     required = Split(Request.Form("_requiredFields"), ",")
     for each name in required
       name = Trim(name)
       if Left(name, 1) <> "_" and Request.Form(name) = "" then
         call AddErrorMsg("Missing value for " & name)
       end if
     next
   end if

   'If a field order was given, use it. Otherwise use the order the fields were
   'received in.

   str = ""
   if Request.Form("_fieldOrder") <> "" then
     fieldOrder = Split(Request.Form("_fieldOrder"), ",")
     for each name in fieldOrder
       if str <> "" then
         str = str & ","
       end if
       str = str & Trim(name)
     next
     fieldOrder = Split(str, ",")
   else
     fieldOrder = FormFieldList()
   end if

   'If there were no errors, build the email note and send it.

   if UBound(errorMsgs) < 0 then

     'Build table of form fields and values.

     body = "<table border=""0"" cellpadding=""2"" cellspacing=""0"">" & vbCrLf
     for each name in fieldOrder
         changedText=Replace(Request.Form(name), chr(13), "<br>")
       body = body _
            & "<tr valign=""top"">" _
            & "<td><b>" & name & ":</b></td>" _
            & "<td>" & changedText & "</td>" _
            & "</tr>" & vbCrLf
     next
     body = body & "</table>" & vbCrLf

     'Add a table for any requested environmental variables.

     if Request.Form("_envars") <> "" then
       body = body _
            & "<p>&nbsp;</p>" & vbCrLf _
            & "<table border=""0"" cellpadding=""2"" cellspacing=""0"">" & vbCrLf
       envars = Split(Request.Form("_envars"), ",")
       for each name in envars
         name = Trim(name)
         body = body _
              & "<tr valign=""top"">" _
              & "<td><b>" & name & ":</b></td>" _
              & "<td>" & Request.ServerVariables(name) & "</td>" _
              & "</tr>" & vbCrLf
       next
       body = body & "</table>" & vbCrLf
     end if

     'Send it.

     str = SendMail()
     if str <> "" then
       AddErrorMsg(str)
     end if

     'Redirect if a URL was given.

     if Request.Form("_redirect") <> "" then
       Response.Redirect(Request.Form("_redirect"))
     end if

   end if %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Form Mail</title>
<style type="text/css">

body {
  background-color: #ffffff;
  color: #000000;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 10pt;
}

table {
  border: solid 1px #000000;
  border-collapse: collapse;
}

td, th {
  border: solid 1px #000000;
  border-collapse: collapse;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 10pt;
  padding: 2px;
  padding-left: 8px;
  padding-right: 8px;
}

th {
  background-color: #c0c0c0;
}

.error {
  color: #c00000;
}

</style>
</head>
<body>

<% if UBound(errorMsgs) >= 0 then %>
<p class="error">Form could not be processed due to the following errors:</p>
<ul>
<%   for each msg in errorMsgs %>
  <li class="error"><% = msg %></li>
<%   next %>
</ul>
<% else %>
<table cellpadding="0" cellspacing="0">
<tr>
  <th colspan="2" valign="bottom">
  Thank you, the following information has been sent:
  </th>
</tr>
<%   for each name in fieldOrder %>
<tr valign="top">
  <td><b><% = name %></b></td>
  <td><% = Request.Form(name) %></td>
</tr>
<%   next %>
</table>
<% end if %>

</body>
</html>

<% '---------------------------------------------------------------------------
   ' Subroutines and functions.
   '---------------------------------------------------------------------------

   sub AddErrorMsg(msg)

     dim n

    'Add an error message to the list.

     n = UBound(errorMsgs)
     Redim Preserve errorMsgs(n + 1)
     errorMsgs(n + 1) = msg

   end sub

   function GetHost(url)

     dim i, s

     GetHost = ""

     'Strip down to host or IP address and port number, if any.

     if Left(url, 7) = "http://" then
       s = Mid(url, 8)
     elseif Left(url, 8) = "https://" then
       s = Mid(url, 9)
     end if
     i = InStr(s, "/")
     if i > 1 then
       s = Mid(s, 1, i - 1)
     end if

     getHost = s

   end function

   'Define the global list of valid TLDs.

   dim validTlds

   function IsValidEmailAddress(emailAddr)

     dim i, localPart, domain, charCode, subdomain, subdomains, tld

     'Check for valid syntax in an email address.

     IsValidEmailAddress = true

     'Parse out the local part and the domain.

     i = InStrRev(emailAddr, "@")
     if i <= 1 then
       IsValidEmailAddress = false
       exit function
     end if
     localPart = Left(emailAddr, i - 1)
     domain = Mid(emailAddr, i + 1)
     if Len(localPart) < 1 or Len(domain) < 3 then
       IsValidEmailAddress = false
       exit function
     end if

     'Check for invalid characters in the local part.

     for i = 1 to Len(localPart)
       charCode = Asc(Mid(localPart, i, 1))
       if charCode < 32 or charCode >= 127 then
         IsValidEmailAddress = false
         exit function
       end if
     next

     'Check for invalid characters in the domain.

     domain = LCase(domain)
     for i = 1 to Len(domain)
       charCode = Asc(Mid(domain, i, 1))
       if not ((charCode >= 97 and charCode <= 122) or (charCode >= 48 and charCode <= 57) or charCode = 45 or charCode = 46) then
         IsValidEmailAddress = false
         exit function
       end if
     next

     'Check each subdomain.

     subdomains = Split(domain, ".")
     for each subdomain in subdomains
       if Len(subdomain) < 1 then
         IsValidEmailAddress = false
         exit function
       end if
     next

     'Last subdomain should be a TDL.

     tld = subdomains(UBound(subdomains))
     if not IsArray(validTlds) then
       call SetValidTlds()
     end if
     for i = LBound(validTlds) to UBound(validTlds)
       if tld = validTlds(i) then
         exit function
       end if
     next
     IsValidEmailAddress = false

   end function

   sub setValidTlds()

     'Load the global list of valid TLDs.

     validTlds = Array("aero", "biz", "com", "coop", "edu", "gov", "info", "int", "mil", "museum", "name", "net", "org", "pro", _
       "ac", "ad", "ae", "af", "ag", "ai", "al", "am", "an", "ao", "aq", "ar", "as", "at", "au", "aw", "az", _
       "ba", "bb", "bd", "be", "bf", "bg", "bh", "bi", "bj", "bm", "bn", "bo", "br", "bs", "bt", "bv", "bw", "by", "bz", _
       "ca", "cc", "cd", "cf", "cg", "ch", "ci", "ck", "cl", "cm", "cn", "co", "cr", "cu", "cv", "cx", "cy", "cz", _
       "de", "dj", "dk", "dm", "do", "dz", "ec", "ee", "eg", "eh", "er", "es", "et", _
       "fi", "fj", "fk", "fm", "fo", "fr", _
       "ga", "gd", "ge", "gf", "gg", "gh", "gi", "gl", "gm", "gn", "gp", "gq", "gr", "gs", "gt", "gu", "gw", "gy", _
       "hk", "hm", "hn", "hr", "ht", "hu", _
       "id", "ie", "il", "im", "in", "io", "iq", "ir", "is", "it", _
       "je", "jm", "jo", "jp", _
       "ke", "kg", "kh", "ki", "km", "kn", "kp", "kr", "kw", "ky", "kz", _
       "la", "lb", "lc", "li", "lk", "lr", "ls", "lt", "lu", "lv", "ly", _
       "ma", "mc", "md", "mg", "mh", "mk", "ml", "mm", "mn", "mo", "mp", "mq", "mr", "ms", "mt", "mu", "mv", "mw ", "mx", "my", "mz", _
       "na", "nc", "ne", "nf", "ng", "ni", "nl", "no", "np", "nr", "nu", "nz", _
       "om", _
       "pa", "pe", "pf", "pg", "ph", "pk", "pl", "pm", "pn", "pr", "ps", "pt", "pw", "py", _
       "qa", _
       "re", "ro", "ru", "rw", _
       "sa", "sb", "sc", "sd", "se", "sg", "sh", "si", "sj", "sk", "sl", "sm", "sn", "so", "sr", "st", "sv", "sy", "sz", _
       "tc", "td", "tf", "tg", "th", "tj", "tk", "tm", "tn", "to", "tp", "tr", "tt", "tv", "tw", "tz", _
       "ua", "ug", "uk", "um", "us", "uy", "uz", _
       "va", "vc", "ve", "vg", "vi", "vn", "vu", _
       "wf", "ws", _
       "ye", "yt", "yu", _
       "za", "zm", "zw")

   end sub

   function FormFieldList()

     dim str, i, name

     'Build an array of form field names ordered as they were received.

     str = ""
     for i = 1 to Request.Form.Count
       for each name in Request.Form
         if Left(name, 1) <> "_" and Request.Form(name) is Request.Form(i) then
           if str <> "" then
             str = str & ","
           end if
           str = str & name
           exit for
         end if
       next
     next
     FormFieldList = Split(str, ",")

   end function

   function SendMail()

     dim mailObj, cdoMessage, cdoConfig
     dim addrList

     'Send email based on mail component. Uses global variables for parameters
     'because there are so many.

     SendMail = ""

     'Send email (CDONTS version). Note: CDONTS has no error checking.

     if mailComp = "CDONTS" then
       set mailObj = Server.CreateObject("CDONTS.NewMail")
       mailObj.BodyFormat = 0
       mailObj.MailFormat = 0
       mailObj.From = fromAddr
       mailObj.Value("Reply-To") = replyTo
       mailObj.To = recipients
       mailObj.Subject = Trim(Request.Form("client_name"))
       mailObj.Body = body
       mailObj.Send
       set mailObj = Nothing
       exit function
     end if

     'Send email (CDOSYS version).

     if mailComp = "CDOSYS" then
       set cdoMessage = Server.CreateObject("CDO.Message")
       set cdoConfig = Server.CreateObject("CDO.Configuration")
       cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
       cdoConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpServer
       cdoConfig.Fields.Update
       set cdoMessage.Configuration = cdoConfig
       cdoMessage.From =  fromAddr
       cdoMessage.ReplyTo = replyTo
       cdoMessage.To = recipients
       cdoMessage.Subject = subject
       cdoMessage.HtmlBody = body
       on error resume next
       cdoMessage.Send
       if Err.Number <> 0 then
         SendMail = "Email send failed: " & Err.Description & "."
       end if
       set cdoMessage = Nothing
       set cdoConfig = Nothing
       exit function
     end if

     'Send email (JMail version).

     if mailComp = "JMail" then
       set mailObj = Server.CreateObject("JMail.SMTPMail")
       mailObj.Silent = true
       mailObj.ServerAddress = smtpServer
       mailObj.Sender = fromAddr
       mailObj.ReplyTo = replyTo
       mailObj.Subject = subject
       addrList = Split(recipients, ",")
       for each addr in addrList
         mailObj.AddRecipient Trim(addr)
       next
       mailObj.ContentType = "text/html"
       mailObj.Body = body
       if not mailObj.Execute then
         SendMail = "Email send failed: " & mailObj.ErrorMessage & "."
       end if
       exit function
     end if

     'Send email (ASPMail version).

     if mailComp = "ASPMail" then
       set mailObj = Server.CreateObject("SMTPsvg.Mailer")
       mailObj.RemoteHost  = smtpServer
       mailObj.FromAddress = fromAddr
       mailObj.ReplyTo = replyTo
       for each addr in Split(recipients, ",")
         mailObj.AddRecipient "", Trim(addr)
       next
       mailObj.Subject = subject
       mailObj.ContentType = "text/html"
       mailObj.BodyText = body
       if not mailObj.SendMail then
         SendMail = "Email send failed: " & mailObj.Response & "."
       end if
       exit function
    end if

   end function %>



</body>



</html>
*************************End Code*****************

many thanks!!
0
Comment
Question by:Tom-J-Lael
  • 11
  • 10
  • 2
  • +1
25 Comments
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 17061669
What email server are you using?  What is the server OS?

You probably need to change the SMTP address or the new server won't allow relaying (sending email through that server from another server/client), and/or you need a login/password to send email via SMTP.
0
 
LVL 3

Author Comment

by:Tom-J-Lael
ID: 17064987
The OS is Windows 2003. The Email Server is ArgoSoft Mail Server Pro. The webpage server IS the Mail Server.
0
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 17071013
Instead of smtp.indyice.com Give, mail.indyice.com

Or otherwise, findout  the smtp from your hosting company.
0
 
LVL 3

Author Comment

by:Tom-J-Lael
ID: 17073802
We are our hosting company (webserver/mailserver is inhouse).

You'll have to forgive me...I'm not a programmer...at all

Do I need code for authentication?
0
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 17079084
I don't find any mistakes in your coding, since, you have told that this was working well in the old server, you have to check your smtp.

Are you able to send mails using your smtp in Outlook Express or any other email client?

If so, try this small coding and test it. Let us see what happens.

<%
Dim myMail, mySub, myBody
Set myMail=CreateObject("CDO.Message")
mySub="Welcome "
myBody="Testing the CDOSYS mail."
myMail.Subject=mySub
myMail.From="workorders@indyice.com"
myMail.To="ohlookitstoppedsnowing@gmail.com"
myMail.TextBody=myBody
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") _
="smtp.indyice.com"
'Server port
myMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") _
=25
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
%>
0
 
LVL 3

Author Comment

by:Tom-J-Lael
ID: 17081707
what do you mean check my SMTP?? The web server is on a mail server who's SMTP is running fine (((web server/mail server...same machine...website in IIS 6.0...mail server is Argo Soft Mail Server...original code posted above does not work even with IIS SMTP installed and started)))

 I'm not a programmer you would have to specify where I should put that code, what I should save it as...etc.
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 17082672
If this was working on the previuos server it was using the IIS SMTP, since your script was setup to use "CDONTS".  IIS 6 is now using "CDOSYS" for SMTP, so you need to make the following changes:

Change this:
     mailComp   = "CDONTS"
To This:
     mailComp   = "CDOSYS"
0
 
LVL 3

Author Comment

by:Tom-J-Lael
ID: 17087349
I don't knwo what the previous server was running...it was third party. However, I changed what you suggested with still no dice. Is there something additional I need to install?? Is the IIS SMTP going to conflict with the Argosoft Mail Server software installed?
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 17087898
That script has no code in it to use Argosoft.
0
 
LVL 3

Author Comment

by:Tom-J-Lael
ID: 17095905
Any idea where I can find script for Argosoft?
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 17095949
I misunderstood you.  I just realized that Argosoft is your email server software on not the email api that you are using.


Actually change the script to:
     mailComp   = "JMail"


Download the free version of JMail.
http://www.dimac.net/default2.asp?M=FreeDownloads/Menu.asp&P=FreeDownloads/FreeDownloadsstart.asp


Is your email server the same machine as the web server?
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 17095958
If the email server is on a different machine then the CDOSYS should have worked.  If that is the case try it again and copy&paste the error you get.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 3

Author Comment

by:Tom-J-Lael
ID: 17096169
The email server IS the same as the webserver. I don't get any error messages. Even after I downloaded and installed JMAIL and changed mailcomp= to "JMAIL".

try it

mail.indyice.com/workorder

Submit works and it goes to a page "thank you your workorder has been submitted"

The email never goes through and the Argosoft Mail Server never logs any activity of the workorder. When using this JMAIl should I turn on the SMTP server in IIS??
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 17096249
How does it end up on thanks.htm???

I found that CDONTS and CDOSYS won't run on a server if another SMTP server is running on that machine.
0
 
LVL 3

Author Comment

by:Tom-J-Lael
ID: 17168245
I moved the webpage to a dedicated IIS 6.0 server with all the latest Windows Updates.

http://mail.indyice.com

Now, the error I get when I hit "Submit" on http://www.indyice.com/workorder is "Page NOt Found" ..."Submit" links to "formmail.asp" . Formmmail.asp is most definetly there so I dont know why I'm getting this new error.
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 17171721
I see you fixed the "Page Not Found" error.

How does it end up on thanks.htm?

I need to see that code to help you out.
0
 
LVL 3

Author Comment

by:Tom-J-Lael
ID: 17174698
I screwed up....www.indyice.com/workorder is the working third party website....I need the script to work on mail.indyice.com/workorder and eventually I'll change the A records for WWW to point to Mail...
0
 
LVL 3

Author Comment

by:Tom-J-Lael
ID: 17175692
Ok...we've now moved the website off of IIS and into APACHE 2.2.2 running on a Windows Server 2003 box.

mail.indyice.com/workorder

 I get an error on the following page

http://mail.indyice.com/workorder/formmail.asp
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 17176666
It's displaying your code.

You may want to start another question "using ASP with Apache".
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 17194187
That's unfortunate, since I spent many hours helping him, but I couldn't get the basic answers to help him.  :-(
0
 
LVL 3

Author Comment

by:Tom-J-Lael
ID: 17196963
It was never explained how to install CDONTs or CDOSYS and I explained multiple times I'm in no way a programmer. I do appreciate your effort though.
0
 
LVL 14

Expert Comment

by:CtrlAltDl
ID: 17196977
I'm sorry, but you never asked how to install CDONTS or CDOSYS.

Did you get it working now?
0
 
LVL 3

Author Comment

by:Tom-J-Lael
ID: 17203344
No.
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 17220301
Closed, 500 points refunded.
Netminder
Site Admin
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now