Avatar of TrueBlue
TrueBlue
Flag for United States of America asked on

Form generates error and no attachment

Hi!

Our web hosting company stopped supporting CDONTs.
So we are trying to implement CDOSYS.
Our original form used CDONTs and ASPUpload to send an attachment.
As you can see we are still using the ASPUpload not sure if needed or not?
Currently, using FF version 19.0.2 an email is generated with no attachment.
The attachment is however stored in the upload directory on the server.
Using IE 10 we just get an error '8004020f' /sendeform.asp, line 99
Line 99 is     ObjSendMail.Send

So obviously we have a problem with this line...

  if len(Filename) > 0 then
      objSendMail.AddAttachment Server.MapPath(Upload.Form("FilePath")) & "\" & Filename
  end if

Not sure what else.

Any specific code corrections would greatly appreciated.

I am sure the server.mappath is correct not sure what equivalent of upload.form("FilePath")
is in CDOSYS
.
Here is our current attempt:

<%@ Language=VBScript%>
<%Response.buffer=true%>
<%
sAllow = "bmp,doc,docx,gif,jpg,pdf,png"
Set Upload = Server.CreateObject("Persits.Upload")

' Limit file size to 100000 bytes, throw an exception if file is larger
Upload.SetMaxSize 100000, True
Upload.SaveToMemory

 For Each File in Upload.Files
      Ext = Lcase(Right(strFileName, 3))
      strFileName = Lcase(File.FileName)

        'test=Server.MapPath(Upload.Form("FilePath") & "\" & strFilename)
        'response.write test ' just for testing
        'response.end() ' just for testing
      
    If instr(sAllow, Ext) Then
      File.SaveAs(Server.MapPath(Upload.Form("FilePath") & "\" & strFilename))
      End If             
 Next

%>
<!-- Include file for CAPTCHA form processing -->            
<!-- #include file="CAPTCHA/new_CAPTCHA_process_form.asp" -->
<%
If "" & Upload.Form("EmailAddress") <> "" Then
    'blnCAPTCHAcodeCorrect = Upload.Form("CAPTCHA_Postback")
    'response.write blnCAPTCHAcodeCorrect
    'response.write Upload.Form("EmailAddress")
    'response.end

    If blnCAPTCHAcodeCorrect <> True then
      Session("Name") = Upload.Form("Name")
      Session("EmailAddress") = Upload.Form("EmailAddress")
      Session("DaytimePhone") = Upload.Form("DaytimePhone")
      Session("Subject") = Upload.Form("Subject")
      Session("StreetAddress") = Upload.Form("StreetAddress")
      Session("City") = Upload.Form("City")
      Session("State") = Upload.Form("State")
      Session("ZipCode") = Upload.Form("ZipCode")
      Session("Message") = Upload.Form("Message")
      'response.write Session("Message")
      'response.end
      Response.Redirect "contact-us.asp?err=captcha"
    Else
   
    strBody = "<!DOCTYPE HTML PUBLIC ""-/W3C//DTD HTML 4.0 Transitional//EN"">" _
         & "<html>" _
         & "<head>" _
         & "<title>" & Upload.Form("Subject") & "</title>" _
         & "<meta http-equiv=Content-Type content=""text/html; charset=iso=8859-1"">" _
         & "</head>" _
         & "<body bgcolor=""#FFFF99"">" _
         & "<h2>" & Upload.Form("Subject") & "</h2>" & "<BR>" _
         & "<p>" _
         & "Name: " & Upload.Form("Name") & "<BR>" _
         & "IP Address: " & Request.ServerVariables("REMOTE_HOST") & "<BR>" _
         & "Daytime Phone No: " & Upload.Form("DaytimePhone") & "<BR>" _
         & "Address: " & Upload.Form("StreetAddress") & "<BR>" _
         & "City: " & Upload.Form("City") & "<BR>" _
         & "State: " & Upload.Form("State") & "<BR>" _
         & "Zip Code: " & Upload.Form("ZipCode") & "<BR>" _
         & "Message: " & Upload.Form("Message") & "<BR>" _
         & "</p>" & "<BR>" _
         & "</body>" & "<BR>" _
         & "</html>" & "<BR>"
         
    Dim ObjSendMail
    Set ObjSendMail = CreateObject("CDO.Message")
   
  ' This section provides the configuration information for the remote SMTP server.
    ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
    ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mail.mydomain.com"
    ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587
    ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
    ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

  ' If your server requires outgoing authentication uncomment the lines below and use a valid email address and password.
   ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
   ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="techserv@mydomain.com"
   ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="xxxxxx"
   
    ObjSendMail.Configuration.Fields.Update
  ' End remote SMTP server configuration section==

  ' Set the properties of the object
    ObjSendMail.Subject = Upload.Form("Subject")
    ObjSendMail.From = Upload.Form("EmailAddress") 'specify senders address
    ObjSendMail.To = "techserv@mydomain.com"
  ' ObjSendMail.Cc = "sales@mydomain.com"
  ' Response.write Server.MapPath(Upload.Form("FilePath")) & "\" & Filename
    if len(Filename) > 0 then
      objSendMail.AddAttachment Server.MapPath(Upload.Form("FilePath")) & "\" & Filename
    end if
    ObjSendMail.HTMLBody = strbody
   
    ObjSendMail.Send
    Set ObjSendMail = Nothing

    Response.Redirect("thankyou.htm")
    If Err <> 0 Then
      Response.Write "Error encountered: " & Err.Description
    End If
   
    End If
   Else %>
   <script language="JavaScript" type="text/javascript">javascript: window.history.back(-1)</script>
 <% End IF %>
ASP

Avatar of undefined
Last Comment
Scott Fell

8/22/2022 - Mon
Scott Fell

if your only problem is the file is not attached, try converting your code to use the full pathname like c:\root\mysite\docs\upload\myfile.jpg

this is the line to change
objSendMail.AddAttachment Server.MapPath(Upload.Form("FilePath")) & "\" & Filename
TrueBlue

ASKER
padas,

I did find one thing I should have used strFilename, but even with your idea of the full pathname there still there is no attachment in the email that is generated.
I checked the server and the file is in the expected directory.
No errors are given.
Checked it with FF & IE 10.
Any other ideas?
ASKER CERTIFIED SOLUTION
Scott Fell

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23