Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cdonts.newmail Corrupts attachments

    I have a webform to mail information and attachments. It sends the mail information from the form fields fine but the attachments end up very corrupted and can not be opened at all. Can anyone take a look here and point me in the right direction to what I'm doing wrong? Thank you much!

    <%


    Set cdomessage = Server.CreateObject("cdo.message")
    'Upload the file
    Set Upload = Server.CreateObject("Persits.Upload")
    Upload.IgnoreNoPost = True
    Count = Upload.SaveVirtual("../upload/")

    'Write out the files uploaded for reference



    For Each File in Upload.Files
    fileName = File.ExtractFileName

    'Start CDONTS
    With CdoMessage
    .From = Upload.Form("email")
    .To = "email address"
    .Subject = "Webform Inquiry"
    .TextBody = "Name: " & Upload.form("fname") & vbCrLf & "Last Name: " & Upload.form("lname") & vbCrLf & "Company: " & Upload.form("company") & vbCrLf & "Trade: " & Upload.form("Trade") & vbCrLf & "Telephone: " & Upload.form("telephone") & vbCrLf & "Email: " & Upload.form("email") & vbCrLf & "Cell: " & Upload.form("cellphone") & vbCrLf & "Location: " & Upload.form("location") & vbCrLf & "Comments: " & Upload.form("Comments")
    cdomessage.AttachFile Server.MapPath("../upload/") & "\" & fileName
    bolAttachmentPosted = ("True")

    cdomessage.BodyFormat = 0 ' CdoBodyFormatHTML
    cdomessage.MailFormat = 0 ' CdoMailFormatMime
    '
    cdomessage.Send
    Set cdomessage = Nothing

    'For Each File in Upload.Files
    fileName = File.ExtractFileName
    FilePathOnServer= Server.MapPath("../upload/")
    FileToDelete = FilePathOnServer & "\" & fileName

    if bolAttachmentPosted =("True") then
    Dim FSO
    'Create a File System Object
    Set FSO = server.CreateObject ("Scripting.FileSystemObject")
    'Delete the file from the server
    FSO.DeleteFile FileToDelete
    'Destroy the object
    Set FSO = Nothing
    end if

    end
    Response.redirect "success.htm"



    %>

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    CDONTS (Collaboration Data Objects for NT) has been Depricated!!! In other words it is not used anymore. CDOSYS is the replacement. In fact The last OS to include CDONTS was Win2k and that was just so people who used it didn't have their code stop working because the replacement was also shipped with Win2K. after that it was not even included. This is a good thing because CDONTS had a lot of bugs and security issues which were fixed with CDOSYS.


    First , you are mixing code that was used by CDONTS and not by CDOSYS. You have the correct object declared For CDOSYS but these 3 lines are from CDONTS

    Code:
    cdomessage.AttachFile Server.MapPath("../upload/") & "\" & fileName
    cdomessage.BodyFormat = 0 ' CdoBodyFormatHTML
    cdomessage.MailFormat = 0 ' CdoMailFormatMime
    Use this instead Note I have abbreviated this to only show the relevant CDO code

    Code:
    Set oCDO = Server.CreateObject("cdo.message")
    With oCDO
          .From = Upload.Form("email")
          .To = "someone@someisp.com"
          .Subject = "Webform Inquiry"
          .TextBody = "Your message"   'used to send as plain ascii text
          '.HTMLBody   is used to send as html formatted mail
          .AddAttachment Server.MapPath("../upload/") & "\" & fileName
          .Send()
    End With
    Set oCDO = Nothing

  • #3
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you very much for pointing that out. It seems to work without errors now with the exception that I never receive any mail. I have assumed that I need to put in the web host's smtp server somewhere in this code, here is what I did, I obviously am doing something wrong. Thanks again.

    I put this in between the upload section and them mailing section:

    Set cdoConfig = CreateObject("CDO.Configuration")



    With cdoConfig.Fields

    .Item(sch & "sendusing") = 2 ' cdoSendUsingPort

    .Item(sch & "smtpserver") = "relay-hosting.secureserver.net"

    .update

    End With
    I've tried with and without this code and cannot get any emails. Even when I comment out the .AddAttachment line I cannot receive the text mail.
    Last edited by j0nnyr0773n; 06-15-2007 at 08:49 PM.

  • #4
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Actually the only time you need to include the configuration settings is if the machine you are using is set so that you need them. This will vary dependant on your webhost.

  • #5
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok thank you for that information. Do you see anything obvious in this script that is not allowing emails to send?

  • #6
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    First off, has your webhost disabled CDO? You can check that by doing a simple test of the object,

    Set oCDO = Server.CreateObject("cdo.message")
    If IsObject(oCDO) Then Response.Write "CDO is Enabled"


    Next check your to email address Like so
    Response.Write "someone@someisp.com"

    This will make sure that you have a good email address

    If they are all good check your spam filters. Quite often spam filters will block the emails because the from address doesn't match the domain that the email is coming from. (only if the from address is not the same domain as the domain the page is on)

  • #7
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you so much for your help, it all works now. I am unsure why it wasn't working before, but I did the last suggestion to check if cdo is enabled and server says it is, I then tried to submit the form and viola! It works. Could I maybe trouble you once more to figure out how to remove the files from the upload folder once they have been emailed? Here's the code I was using but have commented it out for the time being.

    For Each File in Upload.Files
    fileName = File.ExtractFileName
    FilePathOnServer= Server.MapPath("../upload/")
    FileToDelete = FilePathOnServer & "\" & fileName

    if bolAttachmentPosted =("True") then
    Dim FSO

    Set FSO = server.CreateObject ("Scripting.FileSystemObject")

    FSO.DeleteFile FileToDelete

    Set FSO = Nothing
    end if
    Oh and one more thing, it's not a huge deal but I wouldn't mind fixing this if it's fairly simple... I am receiving 2 emails everytime the form is submitted with more than one attachment. I'd love to fix it so it's just one email with 2 attachments instead of 2 emails with one attachment each. Thanks again
    Last edited by j0nnyr0773n; 06-17-2007 at 08:49 PM.

  • #8
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Ok first look where you have your loop.
    Code:
    For Each File in Upload.Files 
         fileName = File.ExtractFileName
    
         'Start CDOSYS
         With CdoMessage
          ......snip
    Next
    In the above code you say that for each file to send you an email. To make it so that all attachments are included in one email simply move the code around a little so that you are sending one email. after you have sent the email , you can delete the files by running another loop and calling the DeleteFile method of the Upload object

    Code:
    'Upload the file
    Set Upload = Server.CreateObject("Persits.Upload") 
    Upload.IgnoreNoPost = True
    Count = Upload.SaveVirtual("../upload/")
    
    'Start CDO
    Set oCdo = Server.CreateObject("CDO.Message")
    With oCdo
    	.From = Upload.Form("email")
    	.To = "email address"
    	.Subject = "Webform Inquiry"
    	.TextBody  = "Name: " & Upload.form("fname") & vbCrLf & "Last Name: " & Upload.form("lname") & vbCrLf & "Company: " & Upload.form("company") & vbCrLf & "Trade: " & Upload.form("Trade") & vbCrLf & "Telephone: " & Upload.form("telephone") & vbCrLf & "Email: " & Upload.form("email") & vbCrLf & "Cell: " & Upload.form("cellphone") & vbCrLf & "Location: " & Upload.form("location") & vbCrLf & "Comments: " & Upload.form("Comments")
    	For Each File in Upload.Files 
    		fileName = File.ExtractFileName
    		.AddAttachment Server.MapPath("../upload/") & "\" & fileName
    	Next
    	.Send()
    End With
    Set oCdo = Nothing
    
    'delete the files from the server
    For Each Item in Upload.Files 
    	FilePathOnServer= Server.MapPath("../upload/") 
    	Upload.DeleteFile FilePathOnServer & "\" & Item 
    Next
    Set Upload = Nothing
    
    Response.redirect "success.htm"

  • #9
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm sorry to keep dragging this on but I am having difficulty still getting only one email. I understand why I am getting two but don't quite understand where to put the code you suggested moving around in order to only get one email here's what I put:

    <%

    Set Upload = Server.CreateObject("Persits.Upload")
    Upload.IgnoreNoPost = True
    Count = Upload.SaveVirtual("../upload/")

    With CdoMessage
    For Each File in Upload.Files
    fileName = File.ExtractFileName
    Next

    Set oCDO = Server.CreateObject("cdo.message")
    With oCDO

    .From = Upload.Form("email")
    .To = "webform@selfcenteredproductions.net"
    .Subject = "Webform Inquiry"
    .TextBody = "Name: " & Upload.form("firstname") & vbCrLf & "Last Name: " & Upload.form("lastname") & vbCrLf & "Company: " & Upload.form("company") & vbCrLf & "Trade: " & Upload.form("Trade") & vbCrLf & "Telephone: " & Upload.form("telephone") & vbCrLf & "Email: " & Upload.form("email") & vbCrLf & "Cell: " & Upload.form("cellphone") & vbCrLf & "Location: " & Upload.form("location") & vbCrLf & "Comments: " & Upload.form("Comments")
    .AddAttachment Server.MapPath("../upload/") & "\" & fileName
    .Send()
    End With
    Set oCDO = Nothing

    next
    Response.redirect "success.htm"



    %>
    Last edited by j0nnyr0773n; 06-18-2007 at 08:12 PM.

  • #10
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Use this code exactly as you see it. don't move the For Each/Next Loop. It needs to be inside the With Statement.

    Code:
    <%
    
    Set Upload = Server.CreateObject("Persits.Upload") 
    Upload.IgnoreNoPost = True
    Count = Upload.SaveVirtual("../upload/")
    
    Set oCDO = Server.CreateObject("cdo.message")
    With oCDO
         .From = Upload.Form("email")
         .To = "webform@selfcenteredproductions.net"
         .Subject = "Webform Inquiry"
         .TextBody = "Name: " & Upload.form("firstname") & vbCrLf & "Last Name: " & Upload.form("lastname") & vbCrLf & "Company: " & Upload.form("company") & vbCrLf & "Trade: " & Upload.form("Trade") & vbCrLf & "Telephone: " & Upload.form("telephone") & vbCrLf & "Email: " & Upload.form("email") & vbCrLf & "Cell: " & Upload.form("cellphone") & vbCrLf & "Location: " & Upload.form("location") & vbCrLf & "Comments: " & Upload.form("Comments")
         ' Loop through and get each file 
         For Each File in Upload.Files
                fileName = File.ExtractFileName
                .AddAttachment Server.MapPath("../upload/") & "\" & fileName
         Next     
         .Send()
    End With
    Set oCDO = Nothing
    
    next
    Response.redirect "success.htm"
    %>
    PS use code tags so that people can see your indenting.
    Last edited by miranda; 06-18-2007 at 10:39 PM.

  • #11
    New to the CF scene
    Join Date
    Jun 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello and Thank You so much for your help and patience with me It works great now. I do get an error saying that the server doesn't support that object for the delete files code, but I can live with emptying the upload folder every so often. Here is the full working code for others who may need it, keep in mind I have the delete files from server area commented out but am leaving it there for others. Thanks again.

    Code:
    <%
    
    Set Upload = Server.CreateObject("Persits.Upload")  
    Upload.IgnoreNoPost = True
    Count = Upload.SaveVirtual("../upload/")
    
    Set oCDO = Server.CreateObject("cdo.message")
    With oCDO
    
    	.From = Upload.Form("email")
    	.To = "webform@selfcenteredproductions.net"
    	.Subject = "Webform Inquiry"
    	.TextBody = "Name: " & Upload.form("firstname") & vbCrLf & "Last Name: " & Upload.form("lastname") & vbCrLf & "Company: " & Upload.form("company") & vbCrLf & "Trade: " & Upload.form("Trade") & vbCrLf & "Telephone: " & Upload.form("telephone") & vbCrLf & "Email: " & Upload.form("email") & vbCrLf & "Cell: " & Upload.form("cellphone") & vbCrLf & "Location: " & Upload.form("location") & vbCrLf & "Comments: " & Upload.form("Comments")
    	
    	For Each File in Upload.Files
                fileName = File.ExtractFileName
    	.AddAttachment Server.MapPath("../upload/") & "\" & fileName
    	Next
    	.Send()
    	End With
    Set oCDO = Nothing
    
    Response.redirect "success.htm"
    
    %>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •