I have written some code to send an email from the server using CDOSYS. When I put a static email address in for the myMail.To= command it works fine but if I try to address a string from a variable (built from a recordset) I only get error '8004020f'. I have tried all I can think of but can't seem to get it to work. I have used Response.Write to write the string to the screen and all looks fine. Can anyone look at my code and help out???? Here's the code...
<% 'build email string for cdosys object below
While ((Repeat1__numRows_a <> 0) AND (NOT expired_members_a.EOF))%>
<span class="report_fields">
<% email_list_a=(expired_members_a.Fields.Item("UserEmail").Value)%>
<% email_list=email_list_a & ";" & email_list
Repeat1__index_a=Repeat1__index_a+1
Repeat1__numRows_a=Repeat1__numRows_a-1
expired_members_a.MoveNext()
Wend
%>
<%'format email string to include quotes
dim qt,address
qt = Chr(34)
address=cStr(qt&email_list&qt)
%>
<% 'send message using cdosys
Set myMail=Server.CreateObject("CDO.Message")
myMail.Subject="my subject!"
myMail.From="from address placed here"
myMail.To=address '***here is where my problem seems to be**
myMail.TextBody="This is a test message"
myMail.Configuration.Fields.Item _
("=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
(" _
="myservername"
'Server port
myMail.Configuration.Fields.Item _
(" _
=25
myMail.Configuration.Fields.Item _
(" _
= 1
myMail.Configuration.Fields.Item _
(" _
= "sendingusername"
myMail.Configuration.Fields.Item _
(" _
= "sendingpassword"
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
%>
Any help would be appreciated.
Thanks
<% 'build email string for cdosys object below
While ((Repeat1__numRows_a <> 0) AND (NOT expired_members_a.EOF))%>
<span class="report_fields">
<% email_list_a=(expired_members_a.Fields.Item("UserEmail").Value)%>
<% email_list=email_list_a & ";" & email_list
Repeat1__index_a=Repeat1__index_a+1
Repeat1__numRows_a=Repeat1__numRows_a-1
expired_members_a.MoveNext()
Wend
%>
<%'format email string to include quotes
dim qt,address
qt = Chr(34)
address=cStr(qt&email_list&qt)
%>
<% 'send message using cdosys
Set myMail=Server.CreateObject("CDO.Message")
myMail.Subject="my subject!"
myMail.From="from address placed here"
myMail.To=address '***here is where my problem seems to be**
myMail.TextBody="This is a test message"
myMail.Configuration.Fields.Item _
("=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item _
(" _
="myservername"
'Server port
myMail.Configuration.Fields.Item _
(" _
=25
myMail.Configuration.Fields.Item _
(" _
= 1
myMail.Configuration.Fields.Item _
(" _
= "sendingusername"
myMail.Configuration.Fields.Item _
(" _
= "sendingpassword"
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
%>
Any help would be appreciated.
Thanks