Help with CDO please

Discussion in 'Classic ASP' started by GBiggs, Aug 22, 2009.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I'm trying to help a client with their classic ASP site - CDOSYS e-mail isn't working. I am an ASP.NET C# coder so it's something of a challenge for me ;-)

    Here is the test script I created. Am I correct that by simply opening the page in the browser the script should execute and generate the mail? If so it ain't working. Thanks

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Test Mail</title>
    </head>
    <body>
    <%
    Dim sMsg [/font]
    Dim sTo
    Dim sFrom
    Dim sSubject
    Dim sTextBody

    sTo = "<my email address here>"
    sFrom = "info@<thewebsitenamehere>.com"
    sSubject = "Test Message"
    sTextBody = "Test message from Foo script"

    Dim objMail
    'Create the mail object
    Set objMail = Server.CreateObject("CDO.Message")

    'Set key properties
    objMail.From = sFrom
    objMail.To = sTo
    objMail.Subject= sSubject
    objMail.TextBody = sTextBody

    'Send the email
    objMail.Send

    'Clean-up mail object
    Set objMail = Nothing
    %>
    </body>
    </html>
     
  2. How about going with this?
    (I created this for many DASP customers using classic ASP here.)

    <%
    strHost = "localhost"
    If Request("Send") <> "" Then
    Set Mail = Server.CreateObject("Persits.MailSender")
    Mail.Host = strHost
    Mail.From = Request("From") ' From address
    Mail.FromName = Request("FromName") ' optional
    Mail.AddAddress "[email protected]", "Mark" 'Request("To")
    Mail.Subject = "Contact page" 'Request("Subject")
    Mail.Body = Request("Body")
    strErr = ""
    bSuccess = False
    On Error Resume Next
    Mail.Send
    If Err <> 0 Then
    strErr = Err.Description
    else
    bSuccess = True
    End If
    End If
    %>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>Contact</title></head>
    <body bgcolor="#FFFFFF">
    <% If strErr <> "" Then %>
    <h3>Error occurred: <% = strErr %></h3>
    <% End If %>
    <% If bSuccess Then %>
    <center><b>Success!</b> Message sent.</center>
    <% End If %>
    <form method="post" action="contact.asp">
    <center>
    <table cellspacing="0" cellpadding="2" width="550" bgcolor="#E0E0E0">
    <tr>
    <td>&nbsp;</td>
    <td align="center"><b>Contact form</b></td>
    </tr>
    <tr>
    <td>Your Email:</td>
    <td><input type="text" name="From" size="50" maxlength="50" /></td>
    </tr>
    <tr>
    <td>Your Name:</td>
    <td><input type="text" name="FromName" size="50" maxlength="50" /></td>
    </tr>
    <tr>
    <td>Message:</td>
    <td><textarea name="Body" cols="40" rows="10"></textarea></td>
    </tr>
    <tr>
    <td colspan="2" align="center"><input type="submit" name="Send" value="Send Message" /></td>
    </tr>
    </table>
    </center>
    </form>
    </body>
    </html>
     
  3. Another pass at it

    Thanks much. Your script ran without error but the mail hasn't arrived ... maybe it will take awhile.

    The error message I was getting with my previous attempt with CDOSYS seemed to have been thrown by lack of authentication. Just for the brain excercise I enhanced the script. Now it throws an error '8004020f' at the
    objMail.send line.

    <%

    Dim argToAddress
    Dim argFromAddress
    Dim argSubject
    Dim argTextBody

    argToAddress = "<my_email>"
    argFromAddress = "<webmaster_email>"
    argSubject = "Test Message"
    argTextBody = "Test message from cdo mail"


    Set objCDOConf = Server.CreateObject ("CDO.Configuration")
    ' ** SET AND UPDATE FIELDS PROPERTIES **
    With objCDOConf
    ' ** OUT GOING SMTP SERVER **
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.<website>.com"
    ' ** TYPE OF AUTHENTICATION **
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
    ' ** USER_ID **
    .Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "<controlpanel_uid>"
    ' ** PASSWORD **
    .Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "<controlpanel_password>"
    ' ** SMTP PORT **
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
    ' ** CDO PORT **
    .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    ' ** TIMEOUT **
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    .Fields.Update
    End With


    Set objMail = Server.CreateObject("CDO.Message")

    ' ** UPDATE THE CDOSYS CONFIGURATION **
    Set objMail.Configuration = objCDOConf

    objMail.From = argFromAddress
    objMail.To = argToAddress
    objMail.Subject = argSubject
    objMail.htmlBody = argBody
    objMail.send

    set objMail = Nothing
    %>
     
  4. ...There is a CDO example in the DASP Support section:

    <%
    set objMessage = createobject("cdo.message")
    set objConfig = createobject("cdo.configuration")

    ' Setting the SMTP Server
    Set Flds = objConfig.Fields
    Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
    Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
    Flds.update


    Set objMessage.Configuration = objConfig
    objMessage.To = "[email protected]"
    objMessage.From = "[email protected]"
    objMessage.Subject = "This is a sample email sent using CDO"
    objMessage.TextBody = "Congratulation" & VbCrLf & "If you receive this is, your mail component works"
    objMessage.fields.update
    objMessage.Send

    Response.write "Mail sent..."

    set objMessage = nothing
    set objConfig = nothing
    %>
     
  5. I don't know if this thread is dead as it was last posted to in August of 2009.

    My experience says that the objMessage.From property has to be a discountasp.net eMail address from your website, like [email protected] (my website is www.kofcri.org so that eMail address is valid). However, the objMessage.To property can be any proper eMail address(es)

    The final post my wisemx contained the key in the Fields collection of the cdo.configuration object.

    Jerry
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page