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!

objmessage.to from recordset 2

Status
Not open for further replies.
Aug 1, 2003
85
US
I'm using this code to send an email when a ticket is placed, except objMessage.TO was my email address. I can't seem to get a variable to work in that line.

<%
If Request.Form("submit").Count > 0 Then

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "TSR Form"
objMessage.Sender = "Martin_Door_Intranet"
objMessage.To = <%=(Recordset1.Fields.Item(emailaddress).Value)%>
objMessage.TextBody = "This TSR was logged by " & Request.Form("FirstName")& " " & Request.Form("LastName")
objMessage.Configuration.Fields.Item _
(" = 2
objMessage.Configuration.Fields.Item _
(" = "mail"
objMessage.Configuration.Fields.Item _
(" = 25
objMessage.Configuration.Fields.Update
objMessage.Send
Set objMessage = Nothing
End If
%>

I can hardcode the email address' in there and get it to work but I'm trying to get them from a recordset. Oh, there could be multiple addresses.

Any Ideas?
Dan
 
try this:

Code:
objMessage.To = Recordset1.Fields.Item("emailaddress").Value

-DNG
 
I get an error

Microsoft VBScript runtime error '800a01a8'

Object required: ''

tsr.asp, line 18

this is line 18
objMessage.To = Recordset1.Fields.Item("emailaddress").Value

I have this
<%=(Recordset1.Fields.Item(emailaddress).Value)%>
in the body and it returns the correct value.

Will this work for multiple addresses?

Dan
 
so that error means your recordset object is not accessible at that level...did you already close your recordset object??

try doing this...

declare a variable and set its value to Recordset1.Fields.Item(emailaddress).Value where you can access the recordset object...

Dim blah
blah=Recordset1.Fields.Item(emailaddress).Value

and then you can use it

objMessage.To = blah

-DNG
 
I had the objmessage.to above the recordset. Now I have

<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_conntesttsrserv_STRING
Recordset1.Source = "SELECT useraccess.emailaddress, pagelinks.pagelinks FROM useraccess INNER JOIN (pagelinks INNER JOIN linkdetail ON pagelinks.pagelinkID = linkdetail.pagelinkIDdetail) ON useraccess.UserID = linkdetail.userID WHERE pagelinks.pagelinks='tsr'"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<%
If Request.Form("submit").Count > 0 Then

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "TSR Form"
objMessage.Sender = "Martin_Door_Intranet"
objMessage.To = Recordset1.Fields.Item("emailaddress").Value
objMessage.TextBody = "This TSR was logged by " & Request.Form("FirstName")& " " & Request.Form("LastName")
objMessage.Configuration.Fields.Item _
(" = 2
objMessage.Configuration.Fields.Item _
(" = "mail"
objMessage.Configuration.Fields.Item _
(" = 25
objMessage.Configuration.Fields.Update
objMessage.Send
Set objMessage = Nothing
End If
%>

That fixed the error but I'm not getting the email. (when I hardcode my email address I get it in about 10 seconds usually.)
Is there a way to see what value is coming from objmessage.to?
Dan
 
I recommend checking to make sure the recordset has at least 1 record before attempting to read values out of its fields. ... I mean check to make srue [tt]Recordset1.EOF[/tt] is False.
 
It does... The record is my email the format is someone@somewhere.com

I also have <%=(Recordset1.Fields.Item(emailaddress).Value)%> in the body and the email is there.
Is there another way to check Recordset1.EOF= false?

I'm having trouble with this code, objMessage.To = Recordset1.Fields.Item("emailaddress").Value

and is there a way to incorporate this
do while not Recordset1.eof
objMessage.to=Recordset1("emailaddress")
Recordset1.movenext
loop
?

Dan


 
what is the error that you are getting...its a better idea to include the .EOF condition but besides that i dont see anything wrong with the code...please post the actual error...

-DNG
 
Did you try something like this?
[tt]
iCount = 0
sTo = ""
do while not Recordset1.eof
'increment counter
iCount = iCount + 1

'Add separator between addresses
if (iCount > 1) then sTo = sTo & ";"

'Append this address to To string
sTo = sTo & Recordset1("emailaddress")

'Move to next address
Recordset1.movenext
loop

'use semi-colon separated string of addresses
objMessage.to = sTo
[/tt]

... or perhaps a comma instead of a semi-colon?
 
For DotNetGnat, I don't get an error. But I don't get the email either.
 
[tt]sendusing = 2
smtpserverport = 25
[/tt]

You are connecting to an email server on your network rather than directly writing to the IIS Virtual SMTP Service


[tt]smtpserver = "mail"[/tt]

The name of your email server is "mail" ... or you have a DNS entry that maps the word "mail" to your mail server
 
For Sheco;

I used the code to no noticable effect. (no error but no email.)

I tried it with sTo = sTo & Recordset1("emailaddress") and sTo = sTo & Recordset1.Fields.Item("emailaddress").Value Is that the correct way to call the record?

Dan
 
Our email server name is mail. Should I be using the IIS Virtual SMTP Service instead?
 
Hold on...I just hardcoded my email address in the objmessage.to and nothing came through. Feel a liitle sheepish ....<running to the server room to kick exchange!!>
 
They are not in the Q. Email server is fine. When I have the Objmessage code after the recordset I get no error but I also get no email. When I put the code at the top I get an error and no email. Unless I hard code my email in the to section then it comes in fine. Here is the code.

<!--#include file="Connections/conntesttsrserv.asp" -->
<%
If Request.Form("submit").Count > 0 Then

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "TSR Form"
objMessage.Sender = "Martin_Door_Intranet"
objMessage.to = "someone@somewhere.com"
objMessage.TextBody = "This TSR was logged by " & Request.Form("FirstName")& " " & Request.Form("LastName")
objMessage.Configuration.Fields.Item _
(" = 2
objMessage.Configuration.Fields.Item _
(" = "mail"
objMessage.Configuration.Fields.Item _
(" = 25
objMessage.Configuration.Fields.Update
objMessage.Send
Set objMessage = Nothing
End If
%>
<%
' *** declare variables
TM_editAction = CStr(Request("URL"))
If (Request.QueryString <> "") Then
TM_editAction = TM_editAction & "?" & Request.QueryString
End If
' boolean to abort record edit
TM_abortEdit = false
%>
<%
' *** Insert Record and retrieve autonumber: set variables
If (CStr(Request("TM_insert")) <> "") Then
MM_editConnection = MM_conntesttsrserv_STRING
TM_editTable = "tsrtest"
TM_editRedirectUrl = "tsrconfirm.asp"
TM_fieldsStr = "FirstName|value|LastName|value|PhoneExt|value|email|value|Department|value|DescriptionofProblem|value|ID|value"
TM_columnsStr = "FirstName|',none,''|LastName|',none,''|PhoneExt|none,none,NULL|email|',none,''|Department|',none,''|DescriptionofProblem|',none,''|ID|none,none,NULL"
' create the TM_fields and TM_columns arrays
TM_fields = Split(TM_fieldsStr, "|")
TM_columns = Split(TM_columnsStr, "|")
' set the form values
For i = LBound(TM_fields) To UBound(TM_fields) Step 2
TM_fields(i+1) = CStr(Request.Form(TM_fields(i)))
Next

' append the query string to the redirect URL
If (TM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, TM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
TM_editRedirectUrl = TM_editRedirectUrl & "?" & Request.QueryString
Else
TM_editRedirectUrl = TM_editRedirectUrl & "&" & Request.QueryString
End If
End If
TM_dontClose = false
Else
TM_dontClose = true
End If
%>
<%
' *** Insert Record and retrieve autonumber for MS Access
' *** ID value is stored in the TM_editCmd("youridcolumn") value
If (CStr(Request("TM_insert")) <> "") Then
' create the sql insert statement
TM_tableValues = ""
TM_dbValues = ""
For i = LBound(TM_fields) To UBound(TM_fields) Step 2
FormVal = TM_fields(i+1)
TM_typeArray = Split(TM_columns(i+1),",")
Delim = TM_typeArray(0)
If (Delim = "none") Then Delim = ""
AltVal = TM_typeArray(1)
If (AltVal = "none") Then AltVal = ""
EmptyVal = TM_typeArray(2)
If (EmptyVal = "none") Then EmptyVal = ""
if (EmptyVal = "NULL") then EmptyVal = ""
If (FormVal = "") Then
FormVal = EmptyVal
Else
If (AltVal <> "") Then
FormVal = AltVal
End If
End If
TM_fields(i+1) = FormVal
Next
If (Not TM_abortEdit) Then
' execute the insert using the AddNew method
set TM_editCmd = Server.CreateObject("ADODB.Recordset")
TM_editCmd.ActiveConnection = MM_editConnection
TM_editCmd.CursorType = 1
TM_editCmd.LockType = 3
TM_editCmd.Source = TM_editTable
TM_editCmd.Open
TM_editCmd.AddNew
For i = LBound(TM_fields) To UBound(TM_fields) Step 2
'If a value for the column name was passed in,
'set the column name equal to the value passed through the form...
if Len(TM_fields(i+1)) > 0 AND TM_fields(i+1)<> "''" then
TM_editCmd.Fields(TM_columns(i)) = TM_fields(i+1)
end if
Next
TM_editCmd.Update
Session("TSRnumber") = TM_editCmd("ID")
If (TM_editRedirectUrl <> "") Then
TM_editCmd.ActiveConnection.Close
Response.Redirect(TM_editRedirectUrl)
End If
End If
End If
%>

<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_conntesttsrserv_STRING
Recordset1.Source = "SELECT useraccess.emailaddress, pagelinks.pagelinks FROM useraccess INNER JOIN (pagelinks INNER JOIN linkdetail ON pagelinks.pagelinkID = linkdetail.pagelinkIDdetail) ON useraccess.UserID = linkdetail.userID WHERE pagelinks.pagelinks='tsr'"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = -1
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
 
I suggest making a test page with only the relavant code.

All of this other cruft is getting in the way.

For example, you might be Redirecting away before the logic for creating the message ever runs.
 
how about using a trim function...

Trim(Recordset1.Fields.Item(emailaddress).Value)

just a guess...may be there are some spaces in the data and the email is not sent because of that...

-DNG
 
oh thats a good guess DNG...

Did you ever do: Response.Write Recordset1("emailaddress")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top