ASP Sending e-mail with CDO

  • pritesh_a
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 15, 2004
  • Posts: 158
  • Loc: South London/UK
  • Status: Offline

Post February 22nd, 2005, 2:49 pm

i want to send e-mails from my website! i.e allow users to create and send emails to who ever!

I have the asp code to send the e-mail, but do i need to create the form for this page i.e. in DWMX?

and just put the code in between the HTML code?

code from http://www.w3schools.com/asp/asp_send_email.asp
<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="mymail@mydomain.com"
myMail.To="someone@somedomain.com"
myMail.HTMLBody = "<h1>This is a message.</h1>"
myMail.Send
%>

or

<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="mymail@mydomain.com"
myMail.To="someone@somedomain.com"
myMail.TextBody="This is a message."
myMail.Send
%>

thanks anyone
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post February 22nd, 2005, 2:49 pm

  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Sep 07, 2004
  • Posts: 2387
  • Loc: Edinburgh, Scotland
  • Status: Offline

Post February 22nd, 2005, 2:55 pm

Well, you'll need to post the values to the ASP page that is to send the email:
Code: [ Download ] [ Select ]
<html>
<head>

</head>
<body>
<form action="send_email_page.asp" method="post">
<p>To:</p>
<input type="text" name="to_field" />
<p>Message:</p>
<textarea name="message_field" rows="5"></textarea>
<input type="submit" value="Send Email" />
</form>
</body>
</html>
  1. <html>
  2. <head>
  3. </head>
  4. <body>
  5. <form action="send_email_page.asp" method="post">
  6. <p>To:</p>
  7. <input type="text" name="to_field" />
  8. <p>Message:</p>
  9. <textarea name="message_field" rows="5"></textarea>
  10. <input type="submit" value="Send Email" />
  11. </form>
  12. </body>
  13. </html>


Then, on your processing page:
Code: [ Download ] [ Select ]
<%
  dim to, message
  to = Request.Form("to_field")
  message = Request.Form("message_field")
  Set myMail=CreateObject("CDO.Message")
  myMail.Subject="Sending email with CDO"
  myMail.From="mymail@mydomain.com"
  myMail.To= to
  myMail.HTMLBody = message
  myMail.Send
%>
  1. <%
  2.   dim to, message
  3.   to = Request.Form("to_field")
  4.   message = Request.Form("message_field")
  5.   Set myMail=CreateObject("CDO.Message")
  6.   myMail.Subject="Sending email with CDO"
  7.   myMail.From="mymail@mydomain.com"
  8.   myMail.To= to
  9.   myMail.HTMLBody = message
  10.   myMail.Send
  11. %>


Obviously you'll need additional processing to check if it's a valid email address, whether the text entered contains illegal characters etc.
Why do geeks get Halloween and Christmas confused?
Because 31 Oct == 25 Dec
www.darren-king.co.uk
  • pritesh_a
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 15, 2004
  • Posts: 158
  • Loc: South London/UK
  • Status: Offline

Post February 22nd, 2005, 2:59 pm

um very helpful thank you katana!!!
im still having problems..i might have to post all the code up!

;-((
  • pritesh_a
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 15, 2004
  • Posts: 158
  • Loc: South London/UK
  • Status: Offline

Post February 22nd, 2005, 3:00 pm

"Obviously you'll need additional processing to check if it's a valid email address, whether the text entered contains illegal characters etc."

what sort of code are we talking?ad refferances?
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Sep 07, 2004
  • Posts: 2387
  • Loc: Edinburgh, Scotland
  • Status: Offline

Post February 22nd, 2005, 3:00 pm

No probs, that's what this place is for ;) :D
Why do geeks get Halloween and Christmas confused?
Because 31 Oct == 25 Dec
www.darren-king.co.uk
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Sep 07, 2004
  • Posts: 2387
  • Loc: Edinburgh, Scotland
  • Status: Offline

Post February 22nd, 2005, 3:02 pm

Well, you'll want to check that the email address at least contains the 'at' symbol (@), otherwise strange and unearthly things may happen.
Why do geeks get Halloween and Christmas confused?
Because 31 Oct == 25 Dec
www.darren-king.co.uk
  • pritesh_a
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 15, 2004
  • Posts: 158
  • Loc: South London/UK
  • Status: Offline

Post February 22nd, 2005, 3:12 pm

right im gona sound so dumb...

iv got two pages in a testing folder on my ISS!(wwwroot)

the folder is called email inside the folder my two files
- email.asp
<html>
<head>

</head>
<body>
<form action="sendemail.asp" method="post">
<p>To:</p>
<input type="text" name="to_field" />
<p>Message:</p>
<textarea name="message_field" rows="5"></textarea>
<input type="submit" value="Send Email" />
</form>
</body>
</html>

and page to
- sendemail.asp
<%
dim to, message
to = Request.Form("to_field")
message = Request.Form("message_field")
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="pri.amin5@hotmail.com"
myMail.To= to
myMail.HTMLBody = message
myMail.Send
%>

this is not working, im not suprised cos i think it looks very wrong
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Sep 07, 2004
  • Posts: 2387
  • Loc: Edinburgh, Scotland
  • Status: Offline

Post February 22nd, 2005, 3:15 pm

What is causing it not to work? What (if any) error message are you getting?
Why do geeks get Halloween and Christmas confused?
Because 31 Oct == 25 Dec
www.darren-king.co.uk
  • pritesh_a
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 15, 2004
  • Posts: 158
  • Loc: South London/UK
  • Status: Offline

Post February 22nd, 2005, 3:19 pm

The page cannot be displayed
There is a problem with the page you are trying to reach and it cannot be displayed.

Please try the following:

* Click the Refresh button, or try again later.
* Open the xx.x.xx.xxx home page, and then look for links to the information you want.

HTTP 500.100 - Internal Server Error - ASP error
Internet Information Services

Technical Information (for support personnel)

* Error Type:
Microsoft VBScript compilation (0x800A03F2)
Expected identifier
/email/sendemail.asp, line 2, column 4
dim to, message
---^

* Browser Type:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.7.5) Gecko/20041110 Firefox/1.0

* Page:
POST 60 bytes to /email/sendemail.asp

* POST Data:
to_field=pri.amin%40gmail.com&message_field=hello+email+test

* Time:
22 February 2005, 22:17:41

* More information:
Microsoft Support

error message!

right another Q, is it safe to give people my IP address to access my website>
i.e
80.108.63.2/email/email.asp

Safe??
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Sep 07, 2004
  • Posts: 2387
  • Loc: Edinburgh, Scotland
  • Status: Offline

Post February 22nd, 2005, 3:24 pm

Just a thought (I don't have Visual Studio at home so no syntax highlighting for me), I think 'to' is a reserved keyword. change it to something else and give it a try (i.e. to_field)
Why do geeks get Halloween and Christmas confused?
Because 31 Oct == 25 Dec
www.darren-king.co.uk
  • pritesh_a
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 15, 2004
  • Posts: 158
  • Loc: South London/UK
  • Status: Offline

Post February 22nd, 2005, 3:29 pm

ok...
in the 2nd page
-sendemail.asp

<%
dim to, message
to = Request.Form("to_field")
message = Request.Form("message_field")
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="pri.amin5@hotmail.com"
myMail.To= to
myMail.HTMLBody = message
myMail.Send
%>

change the above
myMail.To=to
to
myMail.To_Field=to

is that right?
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Sep 07, 2004
  • Posts: 2387
  • Loc: Edinburgh, Scotland
  • Status: Offline

Post February 22nd, 2005, 3:31 pm

No, no. Change the variable 'to':

Code: [ Download ] [ Select ]
<%
dim to_field, message
to_field = Request.Form("to_field")
message = Request.Form("message_field")
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="pri.amin5@hotmail.com"
myMail.To= to_field
myMail.HTMLBody = message
myMail.Send
%>
  1. <%
  2. dim to_field, message
  3. to_field = Request.Form("to_field")
  4. message = Request.Form("message_field")
  5. Set myMail=CreateObject("CDO.Message")
  6. myMail.Subject="Sending email with CDO"
  7. myMail.From="pri.amin5@hotmail.com"
  8. myMail.To= to_field
  9. myMail.HTMLBody = message
  10. myMail.Send
  11. %>
Why do geeks get Halloween and Christmas confused?
Because 31 Oct == 25 Dec
www.darren-king.co.uk
  • pritesh_a
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 15, 2004
  • Posts: 158
  • Loc: South London/UK
  • Status: Offline

Post February 22nd, 2005, 3:35 pm

no
The page cannot be displayed
There is a problem with the page you are trying to reach and it cannot be displayed.

Please try the following:

* Click the Refresh button, or try again later.
* Open the xxx.x.xxx.xxx home page, and then look for links to the information you want.

HTTP 500.100 - Internal Server Error - ASP error
Internet Information Services

Technical Information (for support personnel)

* Error Type:
CDO.Message.1 (0x80040220)
The "SendUsing" configuration value is invalid.
/email/sendemail.asp, line 10

* Browser Type:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.7.5) Gecko/20041110 Firefox/1.0

* Page:
POST 50 bytes to /email/sendemail.asp

* POST Data:
to_field=pri.amin%40gmail.com&message_field=hghfgh

* Time:
22 February 2005, 22:34:23

* More information:
Microsoft Support

do i need a third page for the confirmation page?
and do i need to specify the email address in the code?
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Sep 07, 2004
  • Posts: 2387
  • Loc: Edinburgh, Scotland
  • Status: Offline

Post February 22nd, 2005, 3:45 pm

It's a CDO error this time, which means that the last one has been sorted. Have you set it up so that CDO knows the address of your SMTP server etc?

Google for the text " CDO.Message.1 (0x80040220) ", one of the results is this: http://www.webmasterworld.com/forum47/1941.htm
Why do geeks get Halloween and Christmas confused?
Because 31 Oct == 25 Dec
www.darren-king.co.uk
  • pritesh_a
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 15, 2004
  • Posts: 158
  • Loc: South London/UK
  • Status: Offline

Post February 22nd, 2005, 3:51 pm

are u trying to be funny?
i have to sign up to that fourm!!
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post February 22nd, 2005, 3:51 pm

Post Information

  • Total Posts in this topic: 52 posts
  • Users browsing this forum: No registered users and 213 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.