Unix Technical Forum

Sending email (recipients)

This is a discussion on Sending email (recipients) within the SQL Server forums, part of the Microsoft SQL Server category; --> Follow-up to my original post. Is it possible for the "objEmail.To" to lookup the values from a sqlserver table? ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 08:49 PM
B
 
Posts: n/a
Default Sending email (recipients)

Follow-up to my original post.

Is it possible for the "objEmail.To" 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("CDO.Message")

objEmail.From = "send@test.com"
objEmail.To = "receive@test.com"
objEmail.Subject = "TEST SUBJECT"
objEmail.AddAttachment "\\server\test.csv"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configu
ration/sendusing") = 2
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configu
ration/smtpserver") = "SERVER_NAME"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configu
ration/smtpauthenticate") = 1
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configu
ration/sendusername") = "username"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configu
ration/sendpassword") = "userpwd"
objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configu
ration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send

set objEmail = nothing


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 08:49 PM
Dan Guzman
 
Posts: n/a
Default Re: Sending email (recipients)

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


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("ADODB.Connection")
connection.Open "Provider=SQLOLEDB" & _
";Data Source=MyServer" & _
";Initial Catalog=MyDatabase" & _
";Integrated Security=SSPI"
Set emailAddressRs = _
connection.Execute("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.Close

objEmail.To = recipientList

--
Hope this helps.

Dan Guzman
SQL Server MVP

"B" <no_spam@no_spam.com> wrote in message
news:_ZydndVFodrVxTnZnZ2dnUVZ_omdnZ2d@rcn.net...
> Follow-up to my original post.
>
> Is it possible for the "objEmail.To" 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("CDO.Message")
>
> objEmail.From = "send@test.com"
> objEmail.To = "receive@test.com"
> objEmail.Subject = "TEST SUBJECT"
> objEmail.AddAttachment "\\server\test.csv"
> objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configu
> ration/sendusing") = 2
> objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configu
> ration/smtpserver") = "SERVER_NAME"
> objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configu
> ration/smtpauthenticate") = 1
> objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configu
> ration/sendusername") = "username"
> objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configu
> ration/sendpassword") = "userpwd"
> objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configu
> ration/smtpserverport") = 25
> objEmail.Configuration.Fields.Update
> objEmail.Send
>
> set objEmail = nothing
>
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:27 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com