Sql Server Job VBScript Send Mail

来源:互联网 发布:淘宝孕妇装推荐 编辑:程序博客网 时间:2024/05/23 18:55
Dim jmail,mailBody,fs,txtfs,strsql,strdate
Dim Conn,RsName,strename,strw,strm,rw,strpcp,RsAssis,dtetodate
Dim inttoday
dtetodate=dateadd("d",Date,0)
inttoday = Year(dtetodate)*10000+Month(dtetodate)*100+Day(dtetodate)
set Conn = CreateObject ("ADODB.Connection")
Conn.Open "Provider=MSDataShape; DATA PROVIDER=SQLOLEDB.1;Password=*****;Persist Security Info=True;User ID=***;Initial Catalog=***;Data Source=***"
strsql="exec usp_***** 3"
set RsName=Conn.Execute(strsql)
if not RsName.eof then
       do while not RsName.eof
strdeptlist = "<tr><td align=center height=30>申请单</td><td align=center>" &  RsName("form_no") & "</td><td align=center>" &  RsName("app_name") & "</td><td align=center>" &  RsName("datein") & "</td></tr>"
  Set jmail = CreateObject("JMail.Message") 
strmail=Rtrim(RsName("mail_account"))
strdte=Rtrim(RsName("datein"))
strtype=Rtrim(RsName("absence_des"))
strlogin_name=Rtrim(RsName("login_name"))
strcode=Rtrim(RsName("dept_code"))
strformno=Rtrim(RsName("form_no"))
strappname=Rtrim(RsName("app_name"))
strsql1="select mail_account from am_employee a,RL_DMS_SECURITY1 b where b.emp_id=a.emp_id and conditions like '%" & strcode & "%' and convert(nchar(10),due_date,112)>'"&inttoday&"' and active='y'"
set RsAssis=Conn.Execute(strsql1)
if not RsAssis.eof Then
strml=Rtrim(RsAssis("mail_account"))
jmail.AddRecipient strml
end if
jmail.AddRecipientCC "**@***.com"


set fs = CreateObject("Scripting.FileSystemObject")
set txtf = fs.OpenTextFile("\\**\mail\T***_applicant.htm")
mailBody = ""
if not txtf.atEndOfStream then
mailBody = txtf.ReadAll
end if
mailBody = replace(mailBody,"##todate##",strdte)
mailBody = replace(mailBody,"##type##",strtype)
mailBody = replace(mailBody,"##event##",strdeptlist)
mailBody = replace(mailBody,"##name##",strlogin_name)
jmail.From = "****@qisda.com"
jmail.FromName="***"
jmail.Logging = True
jmail.Silent = True
jmail.ContentType = "text/html"
jmail.Charset = "GB2312" 
jmail.Subject = "提醒您手续未完成"
jmail.Body = ""
jmail.HTMLBody=mailBody
jmail.Send("******")
set jmail = Nothing
set RsAssis=nothing
set fs = Nothing
RsName.movenext
    Loop
end if
set Conn = Nothing
原创粉丝点击