Click here to Skip to main content
16,013,747 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I want to send mails from ASP page.

I used following code:

Set myMail=CreateObject("CDO.Message")
myMail.Subject = "Feedback from PQR.com"
myMail.From = Request.form("tname")
myMail.To = "abc@gmail.com"
myMail.TextBody = Request.form("tmsg")
myMail.Send
set myMail = nothing
Response.Redirect("thank.html")


I guess. I'm missing some initializations in code...:confused:

Do I need to configure the mail A/C???

Thanx In advance!!!
Posted
Updated 17-Nov-10 7:36am
v2

1 solution

VB
dim sName, sEmail, sMessage
    dim oCdoMail, oCdoConf, sConfURL

  if Request.Form("Action") <> "" then
    sName = Request.Form("Name")
    sEmail = Request.Form("Email")
    sMessage = Request.Form("Message")

        Set oCdoMail = Server.CreateObject("CDO.Message")
        Set oCdoConf = Server.CreateObject("CDO.Configuration")

        sConfURL = "http://schemas.microsoft.com/cdo/configuration/"

        with oCdoConf
            .Fields.Item(sConfURL & "sendusing") = 2
            .Fields.Item(sConfURL & "smtpserver") = "localhost"
            .Fields.Item(sConfURL & "smtpserverport") = 25
            .Fields.Update
        end with

        with oCdoMail
            .From = "you@yourdomain.com"
            .To = sEmail
            .Subject = "My message subject"
            .TextBody = sMessage
            .HTMLBody = sMessage
            .Configuration = oCdoConf
            .Send
        end with

        Set oCdoConf = Nothing
        Set oCdoMail = Nothing

    response.write "Thanks for your message!"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900