1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

ASP Code to Send E-Mail

Discussion in 'C#' started by vivek_master146, Jan 10, 2009.

  1. #1
    I am having the following ASP code which is not working. I am using CDOSYS and my server supports it. Now I just just testing this simple code but its not working.:-

    <body>
    <%
    Set myMail=CreateObject("CDO.Message")
    myMail.Subject="Sending email with CDO"
    myMail.From="info@kriti-shawls-scarves.com"
    myMail.To="MY-E-MAIL ID"
    myMail.TextBody="This is a message."
    myMail.Send
    set myMail=nothing
    %>
    </body>
     
    vivek_master146, Jan 10, 2009 IP
  2. tantora

    tantora Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The code looks correct. Do you get an error message? Most likely the proper version of CDONT isn't installed.
     
    tantora, Jan 10, 2009 IP
  3. vivek_master146

    vivek_master146 Peon

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    No, I don't get an error message. I tried both in FF and IE.

    My Server supports CDOSYS and not CDNOTS. Its Window 2003 Server.
     
    vivek_master146, Jan 10, 2009 IP
  4. nyxano

    nyxano Peon

    Messages:
    417
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You could try adding the following lines:

    myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
    myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.server.com"
    myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
    myMail.Configuration.Fields.Update

    ... as your host may need you to specify the mail server emails are to go through. Change "25" to your Outgoing SMTP Mail Port and change "smtp.server.com" to the address or IP of the mail server.

    Without those lines, ASP may be thinking to send emails via the internal email server and if that is disabled (which is on almost all hosts because they have a seperate mail server), no emails will be sent.
     
    nyxano, Jan 11, 2009 IP
  5. nyxano

    nyxano Peon

    Messages:
    417
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Sorry, just thought of it - another option to see if the server supports Persits ASPemail. I find that component quite nice and easy to work with. Not to mention, the Persits web site has tons of examples on how to send various types of emails via that protocol.
     
    nyxano, Jan 11, 2009 IP
  6. MayurGondaliya

    MayurGondaliya Well-Known Member

    Messages:
    1,233
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    170
    #6
    You may also need to include the SMTP authentication. because emails sent without SMTP authentication are blocked by the majority of mail servers on the Internet.
     
    MayurGondaliya, Jan 11, 2009 IP
  7. deltron

    deltron Active Member

    Messages:
    397
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    73
    #7
    I think Mayur may be correct on that.. here is the code I use I just enclose it in a handy class file that I can dumb into projects that need email functionality.

     
    deltron, Jan 11, 2009 IP
  8. vivek_master146

    vivek_master146 Peon

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    How to know my SMTP mail server. What should be in place of smtp.server.com ?

    Should it be the server name on which my site is hosted ?
     
    vivek_master146, Jan 13, 2009 IP
  9. nyxano

    nyxano Peon

    Messages:
    417
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    0
    #9
    If you check your email on that domain using Microsoft Outlook, or other email program - you had to specify the mail server in those settings. You would use that same mail server address here.

    Typically, it is mail.yourdomainname.com but it depends on the hosting company.

    In your Hosting Control Panel, where you create email accounts, it should have the address listed there. If you still can't find it, send a support ticket to your hosting company and ask them what the mail server address is for yourdomainname.com
     
    nyxano, Jan 13, 2009 IP
  10. vivek_master146

    vivek_master146 Peon

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    The mail server is not listed on Hosting CP. I just tried using mail.mydomain.com but its giving error at line 12 which contains mymail.Send Code.

    Ok I will ask my mail server. Do i also need to specify the authentication?
     
    vivek_master146, Jan 13, 2009 IP
  11. vivek_master146

    vivek_master146 Peon

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    OK I got the code. Now the problem is that when i am running asp page directly then email is sending but when i am using POST method from a html page then its not working.

    Is this code alright ?
    
    Dim Subject, Body, SenderEmail, RecipientEmail, SMTPServer,SMTPusername, SMTPpassword,country,company,email,names,fax,phone,comments
    
    SenderEmail = "info@kriti-shawls-scarves.com"
    RecipientEmail= "anilkumar18@vsnl.net"
    country=Request.Form("country")
    company=Request.Form("company")
    email=Request.Form("email")
    names=Request.Form("names")
    fax=Request.Form("fax")
    phone=Request.Form("phone")
    comments=Request.Form("comments")
    Subject = "Hello"
    Body = Body & "comment =  " & comments & VbCrLf
    Body = Body & "Name =  " & names & VbCrLf
    Body = Body & "Email =  " & email & VbCrLf
    Body = Body & "Telephone =  " & phone & VbCrLf
    Body = Body & "country =  " & country & VbCrLf
    Body = Body & "fax =  " & fax & VbCrLf
    Body = Body & "Company =  " & company & VbCrLf
    Code (markup):
     
    vivek_master146, Jan 14, 2009 IP
  12. vivek_master146

    vivek_master146 Peon

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    This is my form code:-

    <form action="mail2.asp" method="post">
    <input type="text" name="names">
    .......................
    .............................
    .
     
    vivek_master146, Jan 14, 2009 IP
  13. vivek_master146

    vivek_master146 Peon

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Woooooo.....

    I got it.
    It should be "POST" not "post"
     
    vivek_master146, Jan 14, 2009 IP