Sending email (recipients)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • B

    Sending email (recipients)

    Follow-up to my original post.

    Is it possible for the "objEmail.T o" to lookup the values from a sqlserver
    table?

    At the moment, I type the email address separated by a semi-colon.

    TIA~



    Set objEmail = CreateObject("C DO.Message")

    objEmail.From = "send@test. com"
    objEmail.To = "receive@test.c om"
    objEmail.Subjec t = "TEST SUBJECT"
    objEmail.AddAtt achment "\\server\test. csv"
    objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    ration/sendusing") = 2
    objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    ration/smtpserver") = "SERVER_NAM E"
    objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    ration/smtpauthenticat e") = 1
    objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    ration/sendusername") = "username"
    objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    ration/sendpassword") = "userpwd"
    objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    ration/smtpserverport" ) = 25
    objEmail.Config uration.Fields. Update
    objEmail.Send

    set objEmail = nothing


  • Dan Guzman

    #2
    Re: Sending email (recipients)

    > Is it possible for the "objEmail.T o" to lookup the values from a sqlserver[color=blue]
    > table?[/color]

    No, but you can easily lookup the values in your script to build the
    objEmail.To string. Below is an untested example:

    Set connection = CreateObject("A DODB.Connection ")
    connection.Open "Provider=SQLOL EDB" & _
    ";Data Source=MyServer " & _
    ";Initial Catalog=MyDatab ase" & _
    ";Integrate d Security=SSPI"
    Set emailAddressRs = _
    connection.Exec ute("SELECT eMailAddress FROM dbo.Contacts")
    recipientList = ""
    Do While emailAddressRs. EOF = False
    If recipientList = "" Then
    recipientList = emailAddressRs. Fields(0).Value
    Else
    recipientList = recipientList & _
    ";" & emailAddressRs. Fields(0).Value
    End If
    emailAddressRs. MoveNext
    Loop
    emailAddressRs. Close
    connection.Clos e

    objEmail.To = recipientList

    --
    Hope this helps.

    Dan Guzman
    SQL Server MVP

    "B" <no_spam@no_spa m.com> wrote in message
    news:_ZydndVFod rVxTnZnZ2dnUVZ_ omdnZ2d@rcn.net ...[color=blue]
    > Follow-up to my original post.
    >
    > Is it possible for the "objEmail.T o" to lookup the values from a sqlserver
    > table?
    >
    > At the moment, I type the email address separated by a semi-colon.
    >
    > TIA~
    >
    >
    >
    > Set objEmail = CreateObject("C DO.Message")
    >
    > objEmail.From = "send@test. com"
    > objEmail.To = "receive@test.c om"
    > objEmail.Subjec t = "TEST SUBJECT"
    > objEmail.AddAtt achment "\\server\test. csv"
    > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    > ration/sendusing") = 2
    > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    > ration/smtpserver") = "SERVER_NAM E"
    > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    > ration/smtpauthenticat e") = 1
    > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    > ration/sendusername") = "username"
    > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    > ration/sendpassword") = "userpwd"
    > objEmail.Config uration.Fields. Item("http://schemas.microso ft.com/cdo/configu
    > ration/smtpserverport" ) = 25
    > objEmail.Config uration.Fields. Update
    > objEmail.Send
    >
    > set objEmail = nothing
    >
    >[/color]


    Comment

    Working...