Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you send e-mail with CDO?

Status
Not open for further replies.

kamfl610

Programmer
Apr 15, 2003
90
US
Okay,

I'm relatively new with ASP pages and need to know how to send e-mail via my web page. I've looked at the CDO coding and i'm having a hard time understanding why it won't work. it keeps timing out. here is my code:

Protected Sub PasswordRecovery1_SendingMail(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MailMessageEventArgs)
Dim dbusername As String
Dim dbemail As String
Dim foundit As Boolean
Dim Conn As New Data.SqlClient.SqlConnection
Dim Command As New Data.SqlClient.SqlCommand
Dim RS As Data.SqlClient.SqlDataReader

Conn.ConnectionString "some information"
Conn.Open()
Command.CommandType = Data.CommandType.Text
Command.CommandText = "Select * from Security"
Command.Connection = Conn
RS = Command.ExecuteReader
Do While RS.Read
dbusername = Trim(RS("UserName"))
If dbusername = PasswordRecovery1.UserName Then
foundit = True
dbemail = Trim(RS("Email"))
Dim objCDO As Object
objCDO = Server.CreateObject("CDO.Message")
objCDO.From = dbemail
objCDO.To = "myemail@email.com"
objCDO.Subject = "Information from domain.com"
objCDO.Body = "Here's the information you requested"
objCDO.Display()
objCDO = Nothing
Exit Do
End If
Loop
If foundit = False Then
PasswordRecovery1.GeneralFailureText = "Your username was not found!"
End If
Conn.Close()
Conn = Nothing


End Sub

This is all within an asp page. Can someone help me figure out what I'm doing wrong? I want this to work with Outlook since everyone here has it. Thanks!
 
Simplify the problem first.

Use this to test and make certain CDO is configured and working on your server.

<%
Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.BodyFormat = 0
objMail.MailFormat = 0
objMail.From = "youremail@yourplace.com"
objMail.To = "theiremeial@theirplace.com"
objMail.Subject = "My subject"
objMail.Body = "Message body"
objMail.Send
Set objMail = Nothing
%>

You will need to change the From and To addresses of course.

If this does not work then CDOnts is not configured on the server. If it does work then you will have to go through your code to find out what else is failing.


Paranoid? ME?? WHO WANTS TO KNOW????
 
NOTE: CDONTS.NewMail works with local SMTP email servers.
If your SMTP server is elsewhere you can use CDO.Message.
You may also have to use .TextBody instead of .Body if using CDO.Message.

My example is for CDONTS. If you happen to be using CDOSYS on the server there will be changes needed in the script.

Paranoid? ME?? WHO WANTS TO KNOW????
 
thanks for the information. I didn't know. I tried the CDONTS and it still keeps timing out. I looked at IIS and it's telling me the SMTP server is running. Soooo....what does that tell me? I'm not sure.....additional help seems necessary now. Thanks!
 
It sounds like the SMTP server may not be configured correctly. Do you send other mail through this server?

Here is a script I found that defines the config directly, try it out and see what happens.

<%
Const cdoSendUsingMethod = "Const cdoSendUsingPort = 2
Const cdoSMTPServer = "Const cdoSMTPServerPort = "Const cdoSMTPConnectionTimeout = "Const cdoSMTPAuthenticate = "Const cdoBasic = 1
Const cdoSendUserName = "Const cdoSendPassword = "Dim objConfig ' As CDO.Configuration
Dim objMessage ' As CDO.Message
Dim Fields ' As ADODB.Fields
' Get a handle on the config object and it's fields
Set objConfig = Server.CreateObject("CDO.Configuration")
Set Fields = objConfig.Fields
' Set config fields we care about
With Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = "smtp_server_name"
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPConnectionTimeout) = 10
.Item(cdoSMTPAuthenticate) = cdoBasic
.Item(cdoSendUserName) = "username"
.Item(cdoSendPassword) = "password"
.Update
End With
Set objMessage = Server.CreateObject("CDO.Message")
Set objMessage.Configuration = objConfig
With objMessage
.To = "Display Name <email_address>"
.From = "Display Name <email_address>"
.Subject = "SMTP Relay Test"
.TextBody = "SMTP Relay Test Sent @ " & Now()
.Send
End With
Set Fields = Nothing
Set objMessage = Nothing
Set objConfig = Nothing
%>

Paranoid? ME?? WHO WANTS TO KNOW????
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top