Dim strConn,Conn,RecObj,strSQL,strSubject,strStatus,strBody,objMail,strDate
Dim intCount,blnBCC,strTeamA,strTeamB,dicGames,strGameID : intCount = 0
Dim strRefInfo,strGameInfo
Const Appending=8
strConn = "Provider=SQLOLEDB;Data Source=WIN-59JDF64IOMC;Initial Catalog=cloudspo_sportsmgr;User Id=cloudspo_sports;password=letmein@cliff64"

Set Conn = CreateObject("adodb.Connection")
With Conn
.ConnectionString  = strConn 
.Open 
End With

blnBCC = "T"

strSQL = "EXECUTE dbo.USP_REF_AUTO_DECLINE"

Set RecObj = CreateObject("adodb.recordset")
With RecObj
.Open strSQL,Conn
Do While .EOF = False
intCount= intCount + 1
strSubject = .Fields("AccpStatus")&" "&.Fields("Name")&" "&.Fields("GameDate")&" "&.Fields("GameTime")&" "&.Fields("HomeTeam")&" vs "&.Fields("AwayTeam")&" @ "&.Fields("Area") & " " & .Fields("GameID")
strBody = strSubject&"<br/>"&.Fields("Comments")&"<br/><br/><span style=""font-size:0.8em""><b>Please Note:</b> These ref accept/decline email notices are sent automatically from SportsManager. To control who these emails are sent to and when they are sent please login to your SportsManager site and click on the Referee Mng area and then click on the Referee Settings area.  You can choose to receive decline emails or both accept and decline notices.</span>"

Set objMail=CreateObject("CDO.Message")
objMail.Subject=strSubject
objMail.From = "notices@sportsmanager.us"
If .Fields("Email") <> "" Then
	objMail.To = .Fields("Email")
	'objMail.To = "bhartiya.ravi@hotmail.com"
Else
	objMail.To = "copy@sportsmanager.us"
End If
If .Fields("Email2") <> ""  Then
	objMail.Cc = .Fields("Email2")
	'objMail.To = "bhartiya.ravi@hotmail.com"
Else
	objMail.Cc = "copy@sportsmanager.us"
End If

If blnBCC = "T" Then
	objMail.BCC = "copy<copy@sportsmanager.us>"
End If 
objMail.HTMLBody = strBody
objMail.Send
Set objMail=Nothing


.MoveNext
Loop
End With
RecObj.Close() : Set RecObj = Nothing : Conn.Close() : Set Conn = Nothing

Set fs=CreateObject("Scripting.FileSystemObject")
Set f=fs.OpenTextFile("C:\ScheduleTask\RefAutoDecline.txt", Appending) 
f.Write VBCRLF&intCount&" Emails Sent Sucessfully At "&Now()&VBCRLF&"------------------"
f.close()
Set fs=Nothing







