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 23rd, 2005, 3:27 am

email.asp
<html>
<head>

</head>
<body>
<form action="sendemail1.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>

sendemail.asp
<%
dim to_field, message
to_field = Request.Form("to_field")
message = Request.Form("message")

'Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

'Out going SMTP server
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smpt.ntlworld.com"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objCDOSYSCon.Fields.Update

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
objCDOSYSMail.From = "pri_amin5@hotmail.com" ' the address you want the email to be from
objCDOSYSMail.TO = to_field 'the address the mail is to be sent to
objCDOSYSMail.Subject = "Subject goes here"
objCDOSYSMail.HTMLBody = message
objCDOSYSMail.Send

'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
%>

ERROR MESSAGE

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 x0.x.x9.xx3 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 (0x80040213)
The transport failed to connect to the server.
/email/sendemail1.asp, line 23

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

* Page:
POST 51 bytes to /email/sendemail1.asp

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

* Time:
23 February 2005, 10:25:45

* More information:
Microsoft Support

SO IN the webpage i can type any email address to send the email?!YES?

in the code i have also sated an email address (pri_amin5@hotmail.com) i think thats wrong!
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post February 23rd, 2005, 3:27 am

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

Post February 23rd, 2005, 3:40 am

You spelled the same of your SMTP server wrong.
You've got "smpt.ntlworld.com" , it should be "smtp.ntlworld.com".
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 23rd, 2005, 3:49 am

*plum*!!

thanks sooooo much mate!!!
it works!!! i recive a message from myself when i check my email!
is there away of changing the name that appears inn the email inbox?

also, how would i create a confirmation page to say message sent?

thanks again mate
sure u dont what 1gb of email storage??
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Sep 07, 2004
  • Posts: 2390
  • Loc: Edinburgh, Scotland
  • Status: Offline

Post February 23rd, 2005, 3:55 am

No probs man, that's what I'm here for.
You could change the .From field to change which address it's from (theoretically, you could use any address).

As for the confirmation page - just use the page that does the sending. So, the code for your "sendemail.asp" file would be:

Code: [ Select ]
<%@ Language=VBScript %>
<html>
<head>

</head>
<body>
<%
dim to_field, message
to_field = Request.Form("to_field")
message = Request.Form("message")

'Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

'Out going SMTP server
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.ntlworld.com"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objCDOSYSCon.Fields.Update

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
objCDOSYSMail.From = "pri_amin5@hotmail.com" ' the address you want the email to be from
objCDOSYSMail.TO = to_field 'the address the mail is to be sent to
objCDOSYSMail.Subject = "Subject goes here"
objCDOSYSMail.HTMLBody = message
objCDOSYSMail.Send

'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
%>
<p>Mail sent successfully to address <%=to_field%>!</p>
</body>
</html>
  1. <%@ Language=VBScript %>
  2. <html>
  3. <head>
  4. </head>
  5. <body>
  6. <%
  7. dim to_field, message
  8. to_field = Request.Form("to_field")
  9. message = Request.Form("message")
  10. 'Create the e-mail server object
  11. Set objCDOSYSMail = Server.CreateObject("CDO.Message")
  12. Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
  13. 'Out going SMTP server
  14. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.ntlworld.com"
  15. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  16. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  17. objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
  18. objCDOSYSCon.Fields.Update
  19. 'Update the CDOSYS Configuration
  20. Set objCDOSYSMail.Configuration = objCDOSYSCon
  21. objCDOSYSMail.From = "pri_amin5@hotmail.com" ' the address you want the email to be from
  22. objCDOSYSMail.TO = to_field 'the address the mail is to be sent to
  23. objCDOSYSMail.Subject = "Subject goes here"
  24. objCDOSYSMail.HTMLBody = message
  25. objCDOSYSMail.Send
  26. 'Close the server mail object
  27. Set objCDOSYSMail = Nothing
  28. Set objCDOSYSCon = Nothing
  29. %>
  30. <p>Mail sent successfully to address <%=to_field%>!</p>
  31. </body>
  32. </html>


If the mail can't be sent, IIS will generate an error (similar to what you were seeing when it wasn't working). Hence, this page will only be displayed if the mail is actually send. Thus, the user only sees the confirmation if there wasn't any errors.
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 23rd, 2005, 3:56 am

thanks again mate,
but when i check my email, the new messgae arrives but NO text is shown!

i think the to files are using two different text areas!!

any comments??

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

Post February 23rd, 2005, 4:07 am

Sorry, replace the line:
Code: [ Select ]
message = Request.Form("message")

With:
Code: [ Select ]
message = Request.Form("message_field")


If you try to retrieve a variable from the form/session/querystring that has not yet been set, you get an empty string, i.e. "". You'd think it would cause an error, but no. That's why you weren't getting the message in the email - the message was set to "".
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 23rd, 2005, 4:15 am

mate your a *peach* genies!!!!!!!

it works! just need to sort out the subject field, for that do i just create a subject field, and name it correctly to what it is called in the code,
i.e. objCDOSYSMail.Subject = "Subject goes here"

oh and the confirmation page does not appear, just a blank page.

Is it unsecure to give out my IP address to access my site to othere peeple??
  • pritesh_a
  • Graduate
  • Graduate
  • No Avatar
  • Joined: Jul 15, 2004
  • Posts: 158
  • Loc: South London/UK
  • Status: Offline

Post February 23rd, 2005, 4:19 am

ooowwwee

This is my 100th post!! Thanks for all your help and sorry if i asked so many dumb Q's, your help is well appreciated
  • katana
  • Mastermind
  • Mastermind
  • User avatar
  • Joined: Sep 07, 2004
  • Posts: 2390
  • Loc: Edinburgh, Scotland
  • Status: Offline

Post February 23rd, 2005, 4:25 am

pritesh_a wrote:
it works! just need to sort out the subject field, for that do i just create a subject field, and name it correctly to what it is called in the code,
i.e. objCDOSYSMail.Subject = "Subject goes here"

oh and the confirmation page does not appear, just a blank page.

Is it unsecure to give out my IP address to access my site to othere peeple??


To add the subject, create another text field on your "post" page, and on the "send" page, create a variable to get the subject field's value. Then, as you say, replace the "Mail.Subject = "Subject goes here"" with the variable and you're laughing!

The confirmation page should appear - did you include the <p>..</p> tags with the confirmation message?

I'm not sure about the IP thing. It will probably be ok, but I don't know.

Glad to be of assistance :D
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 23rd, 2005, 4:35 am

Mail sent successfully to address pri.amin@gmail.com!

ooowwweee working at last!!! thanks mate

Ok just gona try the subject filed, and il get back to u!
thanks again
  • nellaikumar
  • Born
  • Born
  • No Avatar
  • Joined: Feb 15, 2006
  • Posts: 1
  • Loc: Bangalore
  • Status: Offline

Post February 16th, 2006, 12:04 am

Hi,
I am very new this forum. I got the following error while executing Mail code.


My code :


<%
dim to_field, message
to_field = Request.Form("to_field")
message = Request.Form("message")

'Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

'Out going SMTP server
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smpt.ntlworld.com"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objCDOSYSCon.Fields.Update

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
objCDOSYSMail.From = "nellaikumar2002@rediffmail.com" ' the address you want the email to be from
objCDOSYSMail.TO = to_field 'the address the mail is to be sent to
objCDOSYSMail.Subject = "Subject goes here"
objCDOSYSMail.HTMLBody = message
objCDOSYSMail.Send

'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
%>

Error Message :

Technical Information (for support personnel)

Error Type:
CDO.Message.1 (0x80040213)
The transport failed to connect to the server.
/16/cdosys/sendemail.asp, line 24


Seeks help regarding this CDOSYS Mail.

Thanks,
P.Nellaikumar.
nellaikumar2002@rediffmail.com

pritesh_a wrote:
*plum*!

thanks sooooo much mate!
it works! i recive a message from myself when i check my email!
is there away of changing the name that appears inn the email inbox?

also, how would i create a confirmation page to say message sent?

thanks again mate
sure u dont what 1gb of email storage??
  • Jereme.Guenther
  • Born
  • Born
  • No Avatar
  • Joined: May 01, 2006
  • Posts: 1
  • Status: Offline

Post May 1st, 2006, 4:59 pm

I have been fighting a similar issue myself. I have my own server on which I installed windows 2003, iis6, SMTP virtual server. I have pointed my SMTP server to my companies personal smart host. I have finally succeeded in getting the following code to run correctly:

Code: [ Select ]
  Set cdoConfig = CreateObject("CDO.Configuration")

  With cdoConfig.Fields
    .Item(cdoSendUsingMethod) = cdoSendUsingPort
    .Item(cdoSMTPServer) = "localhost"
    .Item(cdoSMTPAuthenticate) = cdoNTLM
'    .Item(cdoSendUsername) = "username"
'    .Item(cdoSendPassword) = "password"
    .Update
  End With

    Set theMail= CreateObject("CDO.Message")
    theMail.Configuration = cdoConfig
    Select Case EmailBodyStyle
        Case "text"
            theMail.TextBody=EmailBody
        Case "html"
            theMail.HTMLBody=EmailBody
    End Select
    theMail.From=EmailFrom
    theMail.To=EmailTo
    theMail.subject=EmailSubject
    theMail.Send
    set theMail = Nothing
        Set cdoConfig = Nothing
  1.   Set cdoConfig = CreateObject("CDO.Configuration")
  2.   With cdoConfig.Fields
  3.     .Item(cdoSendUsingMethod) = cdoSendUsingPort
  4.     .Item(cdoSMTPServer) = "localhost"
  5.     .Item(cdoSMTPAuthenticate) = cdoNTLM
  6. '    .Item(cdoSendUsername) = "username"
  7. '    .Item(cdoSendPassword) = "password"
  8.     .Update
  9.   End With
  10.     Set theMail= CreateObject("CDO.Message")
  11.     theMail.Configuration = cdoConfig
  12.     Select Case EmailBodyStyle
  13.         Case "text"
  14.             theMail.TextBody=EmailBody
  15.         Case "html"
  16.             theMail.HTMLBody=EmailBody
  17.     End Select
  18.     theMail.From=EmailFrom
  19.     theMail.To=EmailTo
  20.     theMail.subject=EmailSubject
  21.     theMail.Send
  22.     set theMail = Nothing
  23.         Set cdoConfig = Nothing


Just thought I would pass this along. I have another windows 2003 server running iis6, SMTP Virtual... just like my first one and I can get it to run just fine without the CDO.Configuration code, however I must admit that even though it runs without errors it has recently quit sending off the email.

However, the biggest stumbling block for me when upgrading this code from the original CDONTS code was that I forgot to install SMTP on the new server. I am still confused as to why I need the CDO.Configuration code as all that information should default for me, but at least it is working.

Oh, I forgot to mention that it also took me a bit to figure out that the old adovbs file was replaced with:
Code: [ Select ]
<!--METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" NAME="CDO for Windows 2000 Library" -->
<!--METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4" NAME="ADODB Type Library" -->
  1. <!--METADATA TYPE="typelib" UUID="CD000000-8B95-11D1-82DB-00C04FB1625D" NAME="CDO for Windows 2000 Library" -->
  2. <!--METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4" NAME="ADODB Type Library" -->
  • mkhawarbashir
  • Born
  • Born
  • No Avatar
  • Joined: May 30, 2006
  • Posts: 3
  • Status: Offline

Post May 30th, 2006, 1:04 am

I have made a page to run the same code but getting this message while it is called from otherpage.

Open IIS Help, which is accessible in IIS Manager (inetmgr), and search for topics titled Web Site Setup, Common Administrative Tasks, and About Custom Error Messages

can u tell what and where the problem is? i will be thankful.
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23404
  • Loc: Woodbridge VA
  • Status: Offline

Post May 30th, 2006, 5:41 am

You didn't specify the actual error, mkhawarbashir

What is the actual error message and can you post the mail code you are using as well?
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
  • mkhawarbashir
  • Born
  • Born
  • No Avatar
  • Joined: May 30, 2006
  • Posts: 3
  • Status: Offline

Post June 1st, 2006, 1:35 am

This is the code written in asp file

<%

Dim varfrom, varto, varsubject, varcomments,t1name
varfrom=Request.Form("txtfrom")
varto=Request.Form("listto")
varsubject=Request.Form("txtsubject")
varcomments=Request.Form("txtcomments")

dim objCDOSYSMail, objCDOSYSCon
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")

'Out going SMTP server
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.uvas.edu.pk"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objCDOSYSCon.Fields.Update

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
objCDOSYSMail.From = varfrom
objCDOSYSMail.TO = varto
objCDOSYSMail.Subject = varsubject
objCDOSYSMail.HTMLBody = varcomments
objCDOSYSMail.Send
Set objCDOSYSMail=Nothing
Response.write "Thank You"
%>

and receiving following error message

Please try the following:

Make sure that the Web site address displayed in the address bar of your browser is spelled and formatted correctly.
If you reached this page by clicking a link, contact the Web site administrator to alert them that the link is incorrectly formatted.
Click the Back button to try another link.
HTTP Error 404 - File or directory not found.
Internet Information Services (IIS)

--------------------------------------------------------------------------------

Technical Information (for support personnel)

Go to Microsoft Product Support Services and perform a title search for the words HTTP and 404.
Open IIS Help, which is accessible in IIS Manager (inetmgr), and search for topics titled Web Site Setup, Common Administrative Tasks, and About Custom Error Messages.


I will wait for ur reply
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post June 1st, 2006, 1:35 am

Post Information

  • Total Posts in this topic: 52 posts
  • Users browsing this forum: No registered users and 223 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
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.