Sending email using CDO

Last post 05-13-2009 6:15 AM by matthisco. 2 replies.

Sort Posts:

  • Sending email using CDO

    05-12-2009, 7:15 AM
    • Member
      6 point Member
    • matthisco
    • Member since 06-04-2008, 7:21 AM
    • Posts 163

     Hi, Sorry if this is the wrong forum.

    I'm trying to send an email uding CDO. Can anyone please help?

     form ---------------------

    <form action="mail.asp" method="post" name="mailform">
    <input name="email" type="text" size="40"/>
    <input name="email_submit" type="submit"
    value="sendmail"/>
    </form>

    code----------------------------

    <%
    dim oCdoMsg, oCdoConfg, strReferer, strServer, strClientIP, strServerIP, blnSpam

    set oCdoMsg = server.createobject("CDO.Message")

    strReferer = request.servervariables("HTTP_REFERER")
    strServer = Replace(request.servervariables("SERVER_NAME"), "www.", "")
    strClientIP = request.servervariables("REMOTE_ADDR")
    strServerIP = request.servervariables("LOCAL_ADDR")
    strFrom = "noreply@" & strServer

    intComp = inStr(strReferer, strServer)
    If intComp > 0 Then
    blnSpam = False
    Else
    ' Spam Attempt Block
    blnSpam = True
    End If


    oCdoMsg.to = request.form("email")
    oCdoMsg.from = strFrom
    oCdoMsg.Subject = "CDO Test Mail"
    oCdoMsg.Textbody = "This test mail has been sent from server "
    oCdoMsg.Textbody = oCdoMsg.Textbody & request.servervariables("LOCAL_ADDR") & " via CDO mail objects."

    strMSSchema = "http://schemas.microsoft.com/cdo/configuration/"
    Set oCdoConfg = Server.CreateObject("CDO.Configuration")
    oCdoConfg.Fields.Item(strMSSchema & "sendusing") = 2
    oCdoConfg.Fields.Item(strMSSchema & "smtpserver") = "smtp.fasthosts.co.uk"
    oCdoConfg.Fields.Update
    Set oCdoMsg.Configuration = oCdoConfg

    If NOT blnSpam Then
    oCdoMsg.send
    strResult = "Mail Sent."
    Else
    strResult = "Mail Not Sent."
    End If
    response.write strResult

    set oCdoMsg = nothing
    set oCdoConfg = nothing

    %>

    error:

     error '8004020f'

    /mail.asp, line 35

  • Re: Sending email using CDO

    05-12-2009, 7:40 AM
    • All-Star
      25,881 point All-Star
    • qwe123kids
    • Member since 03-27-2008, 9:49 AM
    • Mumbai
    • Posts 4,403

    Hi,

     

    //Mail code U look the link below

    http://support.jodohost.com/showthread.php?p=52440

     Reason for error may The SMTP server may Be rejecting the Mail or More Information Check the below link

    http://classicasp.aspfaq.com/email/why-does-cdo-message-give-me-8004020f-errors.html

    Check the above link


    Thanks
    Avinash Tiwari

    Remember to click “Mark as Answer” on the post, if it helps you.

    MY Blog

    Hacking Inside .net exe
  • Re: Sending email using CDO

    05-13-2009, 6:15 AM
    • Member
      6 point Member
    • matthisco
    • Member since 06-04-2008, 7:21 AM
    • Posts 163

     Thanks for you reply, I have this working now. However, do you know how I can guard against spam?

    My code is below, thankyou again

    <%

    Sub sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer)
    Set MyMail = CreateObject("cdo.message")
    MyMail.From = mailFrom
    MyMail.To = mailTo
    MyMail.Subject = mailSubject
    MyMail.HTMLBody = mailMessage
    MyMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mailServer
    MyMail.Configuration.Fields.Update
    MyMail.Send
    Set MyMail = nothing
    End Sub

    Dim mailFrom, mailTo, mailSubject, mailMessage, mailServer

    mailFrom = "xx@xx.nhs.uk"
    mailTo = "xxx@xx.co.uk"
    mailSubject = "This is my subject"
    mailMessage = "<html><body>This is my message</body><html>"
    mailServer = "smtp.fasthosts.co.uk"

    Call sendEmail(mailFrom, mailTo, mailSubject, mailMessage, mailServer)
    %>

Page 1 of 1 (3 items)