PDA

Click to See Complete Forum and Search --> : objEMail problem


parakeet
Aug 8th, 2000, 06:38 AM
I'm working on ASP aplication which send emails.
I want get email add from DB,but I need to put "," between each email add like

>objEMail.To = "email_add_1,email_add_2,..."

Then I have no idea how to put ",".
I'm writing a script like below.

><%
> dim Email(10)
> NoOfEmails = 0
> set conntemp=server.createobject("adodb.connection")
> DSN_Name = GetDSN("***")
> conntemp.open DSN_Name
> set rstemp=conntemp.execute("select email from email_table where dept='Sales'")

> do while not rstemp.eof
> NoOfEmail = NoOfEmail + 1
> Email(NoOfEmail) = rstemp(0)
>
> rstemp.movenext
> loop
> rstemp.close
> for x = 1 to NoOfEmail
> %>
> objEMail.To ="<%=Email(x)%>"
><%
> Next

Dose anyone know how to do this?
Please advice.

Aug 9th, 2000, 06:21 AM
<%
dim Email(10)
NoOfEmails = 0
set conntemp=server.createobject("adodb.connection")
DSN_Name = GetDSN("***") ' BTW: What's this all about...your own function?
conntemp.open DSN_Name
set rstemp=conntemp.execute("select email from email_table where dept='Sales'") ' Strange way to do it...I'd use: rstemp.open "select email from email_table where dept='Sales'", conntemp
do while not rstemp.eof
NoOfEmail = NoOfEmail + 1
Email(NoOfEmail) = rstemp(0)

rstemp.movenext
loop

rstemp.close
for x = 1 to NoOfEmail
objEMail.To=Email(x) & ", "
Next

objEMail.To = left(objEMail.To, len(objEMail.To) - 2 ) ' Trim off the last ", "

%>

parakeet
Aug 9th, 2000, 08:45 AM
Thanks very much!!
Sorry that my codes included my own function.

Thanks again.

Aug 9th, 2000, 10:34 AM
Tis OK. I dont't care. It just had me a bit confused to start with. Thought it was some cool function to look up all the DNSes on a host machine. :) Was right disappointed when I couldn't find it in MSDN. :( :D

parakeet
Aug 10th, 2000, 02:27 AM
I'm having problem.

If I do like
<%
for x = 1 to NoOfEmail
objEMail.To=Mail_add
Mail_add=Email(x) & ", "
Next
response.write Mail_add

objEMail.To = left(Mail_add, len(Mail_add) - 2 )

%>

Then I get only first value, though I need get them like
Email(1),Email(2),Email(3),....Email(x), .

How do I put them that way?
Please help.

Aug 10th, 2000, 04:30 AM
I'd have thought that woudl have worked. Erm...maybe the To property is write only...so every time you do something like

objEMail.to = objEMail.to & "matthew@ralston.net"

it's like writing

objEMail.to = "" & "matthew@ralston.net"

Get what I'm on about? Dunno if I've explained it very well.
Try building up the "to" line in a temporary variable first then put it into objEMail.To

parakeet
Aug 10th, 2000, 04:59 AM
I'm confused...
I think my last code was very confusing.

Now I write the code below, then I want "response.write Send_Dept" give me the line next.

" Email(1),Email(2),Email(3),....Email(x), . "
But it only gives me back the first value.

<%
for x = 1 to NoOfEmail
Send_Dept=E_mail(x) & ", "
Next

response.write Send_Dept

objEMail.To = left(Send_Dept, len(Send_Dept) - 2 )
%>

I feel like I'm not explaining well...
Wish you get what I mean.

Thanks

Aug 10th, 2000, 05:36 AM
(Sigh). Erm...dunno...perhaps NoOfEmail has a value of 0 or 1 or something for some reason?

parakeet
Aug 10th, 2000, 05:42 AM
Well,thanks anyway.
I appreciate your replies.

I guess what I need to know here is " How to put values in ' Value(1),Value(2),...Value(x)' style". So I think I will put new thread about this.

parakeet
Aug 10th, 2000, 08:10 AM
My DB master taught me new way to solve my original question.
It DOES work. So FYI, I leave codes below.
Isn't it useful?

<%
set conntemp=server.createobject("adodb.connection")
conntemp.open DSN_Function
set rstemp=conntemp.execute("select email from email_table where dept='Sales'")
set objEMail = Server.CreateObject("CDONTS.NewMail")
EmailTxt = ""

do while not rstemp.eof

If not isnull(rstemp(0)) then
EmailTxt = EmailTxt & rstemp(0) & ", "
end if

rstemp.movenext
loop

rstemp.close
set rstemp = nothing
set conntemp = nothing

objEMail.To = left(EmailTxt, len(EmailTxt) - 2)

%>

>matthewralston
Using left function this way is very neat, I think.

Aug 10th, 2000, 05:16 PM
Ah...so you found a REAL expert! :p
Good on ya. :)