Results 1 to 11 of 11

Thread: objEMail problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    16

    Smile

    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.


  2. #2
    Guest
    Code:
    <% 
    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 ", "
    
    %>

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    16

    Smile Thanks!

    Thanks very much!!
    Sorry that my codes included my own function.

    Thanks again.


  4. #4
    Guest
    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.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    16

    Smile how to put values in order?

    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.

  6. #6
    Guest
    I'd have thought that woudl have worked. Erm...maybe the To property is write only...so every time you do something like

    Code:
    objEMail.to = objEMail.to & "[email protected]"
    it's like writing

    Code:
    objEMail.to = "" & "[email protected]"
    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

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    16

    Smile mmm...

    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


  8. #8
    Guest
    (Sigh). Erm...dunno...perhaps NoOfEmail has a value of 0 or 1 or something for some reason?

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    16

    Smile Thanks anyway

    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.


  10. #10

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    16

    Smile

    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.


  11. #11
    Guest
    Ah...so you found a REAL expert!
    Good on ya.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width