I am using activeX script in a DTS package to send mail to serveral users if thier ID is found in a particular MSSQL view. The code is added below. it is only sending one email for the first employee it finds in the view. Please help me modify the code so that it could send an email for each employee it finds and add the id of each COntent_ID it finds for each employee.
For testing I am only including my email address and not yet getting the email address from the view. I will modify that latr
Sub Send_Mail(strTo, strFrom, strSubject, strMessage )
Const cdoSendUsingPickup = 1
Const cdoSendUsingPort = 2
set iMsg = CreateObject("CDO.Message"
)
set iConf = CreateObject("CDO.Configur
ation")
Set Flds = iConf.Fields
With Flds
.Item("
http://schemas.microsoft.com/cdo/configuration/sendusing") =2 'cdoSendUsingPort
'this parameter below is the valid SMPT Server Name
.Item("
http://schemas.microsoft.com/cdo/configuration/smtpserver")
="******.***.com"
.Item("
http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
) = 10
.Update
End With
With iMsg
Set .Configuration = iConf
.To = strTo ' comma separated list of recipients.
.From = strFrom
.Subject = strSubject
.HTMLBody = strMessage
.Send
End With
End Sub
Function Main()
dim myConn
dim myRecordset
dim iRowCount
dim rsUnread
' instantiate the ADO objects
set myConn = CreateObject("ADODB.Connec
tion")
set myRecordset = CreateObject("ADODB.Record
set")
set rsUnread = CreateObject("ADODB.Record
set")
' set the connection properties to point to the CMS database using the ProcessDisplay view
myConn.Open = "Provider=SQLOLEDB.1;Data Source=******; Initial Catalog=*******;user id = '********';password='*****
'"
' check for unread documents for each emloyee
mySQLUnread = "Select Emp_ID from vProcessDisplay"
rsUnread.Open mySQLUnread, myConn
For xcnt = 0 to rsUnread.fields.count -1
mySQLCmdText = "Select 'rowcount' = Count(*), Contetn_ID, Content_title,Emp_Name, Reading_Group, email from vProcessDisplay where emp_ID = '" & rsUnread("Emp_ID") & "' group by Content_ID, COntent_title, emp_Name, Reading_Group, email"
myRecordset.Open mySQLCmdText, myConn
set Flds = myRecordset.Fields
set iRowCount = Flds("rowcount")
next
while not myRecordset.eof
If iRowCount.Value = 0 then
Main = DTSTaskExecResult_Failure
else
dim unreaddoc
unreaddoc = iRowCount.Value
strTo="myname<myemailaddrs
s@*******.
com>"
strFrom="Document Central<process@****.*****
*.com>"
strSubject="Unread document for -" & Date() & myRecordset("emp_Name")
' I would like to have a loop here that adds each content_ID to the message as there may be more than one document for each employee
strMessage="There are " & unreaddoc & " documents to be read "
Send_Mail strTo, strFrom, strSubject, strMessage
Main = DTSTaskExecResult_Success
End If
myRecordset.movenext
wend
Main = DTSTaskExecResult_Success
End Function
Start Free Trial