????????HTTP?? DLL??????SOAP??????????OLE Automation??????????????????????CreateObject() ???
??????VBS?????????HTTP?? DLL?CreateObject()???£?
????Dim http
????Set http = CreateObject("Msxml2.XMLHTTP")
????Dim dll
????Set dll = CreateObject("??????.????")
????2. ???
????(1)  ??????/??ó????У??????????SMTP??????????SMTP?????????
????(2) ???????????Windows????????????OLE Automation??
????VBS??????????£?
Dim ns
ns = "http://schemas.microsoft.com/cdo/configuration/"
Dim title?? content
title = "db_maint_alert"
content = ""
content = content&"Hi All??"
content = content&chr(13)&chr(10)
content = content&" "
content = content&chr(13)&chr(10)
content = content&"----test mail----"
Msgbox('~1~')
Set cm = CreateObject("CDO.Message")
cm.from = "from_user_name@abc.com"
cm.to = "to_user_name@abc.com"
cm.cc = "cc_user_name@abc.com"
cm.subject = title
cm.textbody = content
'cm.AddAttachment ""
Msgbox('~2~')
'sendusing: 1 = pickup?? 2 = port
'smtpauthenticate: 0 = anonymous??1 = common??2 = NTLM
'smtpusessl: 0 = no??1 = yes
With cm.configuration.fields
.item(ns & "sendusing") = 2
.item(ns & "smtpserver") = "xxx.xxx.xxx.xxx"
.item(ns & "smtpserverport") = 25
.item(ns & "smtpauthenticate") = 1
.item(ns & "sendusername") = "user_name@abc.com"
.item(ns & "sendpassword") = "*****************"
.item(ns & "smtpconnectiontimeout") = 10
.item(ns & "smtpusessl") = 0
.update
End With
Msgbox('~3~')
cm.send
Set cm = nothing
Msgbox('~success~')
????SQL Server 2000??????????£?
????SQL Server 2000??SQL Mail??????????????????????????????MAPI??????????磺OUTLOOK?????SQL Mail????????????ó????MAPI?????????????????????????????????????????VBS??OLE Automation??????
use master;
if OBJECT_ID('sp_SendDatabaseMail') is not null
drop proc sp_SendDatabaseMail
go
CREATE PROCEDURE sp_SendDatabaseMail
@recipients varchar(8000)?? --'001@abc.com; 002@abc.com;'
@Subject    varchar(400) = ''??
@HtmlBody   varchar(8000) = ''
as
Declare @From varchar(100)
Declare @To varchar(100)
Declare @Bcc varchar(500)
Declare @AddAttachment varchar(100)
Declare @object int
Declare @hr int
Declare @source varchar(255)
Declare @description varchar(500)
Declare @output varchar(1000)
set @From = 'SqlAlert@abc.com'
set @To = @recipients
set @Bcc = ''
set @AddAttachment = ''
--set @HtmlBody= '<body><h1><font color=Red>' +@HtmlBody+'</font></h1></body>'
EXEC @hr = sp_OACreate 'CDO.Message'?? @object OUT
EXEC @hr = sp_OASetProperty @object?? 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value'??'2'
EXEC @hr = sp_OASetProperty @object?? 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value'?? 'xxx.xxx.xxx.xxx'
EXEC @hr = sp_OASetProperty @object?? 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport").Value'??'25'
EXEC @hr = sp_OASetProperty @object?? 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate").Value'??'1'
EXEC @hr = sp_OASetProperty @object?? 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusername").Value'??'user_name@abc.com'
EXEC @hr = sp_OASetProperty @object?? 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendpassword").Value'??'*****************'
EXEC @hr = sp_OAMethod @object?? 'Configuration.Fields.Update'?? null
EXEC @hr = sp_OASetProperty @object?? 'To'?? @To
EXEC @hr = sp_OASetProperty @object?? 'Bcc'?? @Bcc
EXEC @hr = sp_OASetProperty @object?? 'From'?? @From
EXEC @hr = sp_OASetProperty @object?? 'Subject'?? @Subject
EXEC @hr = sp_OASetProperty @object?? 'HtmlBody'?? @HtmlBody
--add attachment
if @AddAttachment<>''
EXEC @hr = sp_OAMethod @object?? 'AddAttachment'??NULL??@AddAttachment
IF @hr <>0
select @hr
BEGIN
EXEC @hr = sp_OAGetErrorInfo NULL?? @source OUT?? @description OUT
IF @hr = 0
BEGIN
SELECT @output = ' Source: ' + @source
PRINT @output
SELECT @output = ' Description: ' + @description
PRINT @output
END
ELSE
BEGIN
PRINT ' sp_OAGetErrorInfo failed.'
RETURN
END
END
--send mail
EXEC @hr = sp_OAMethod @object?? 'Send'?? NULL
IF @hr <>0
select @hr
BEGIN
EXEC @hr = sp_OAGetErrorInfo NULL?? @source OUT?? @description OUT
IF @hr = 0
BEGIN
SELECT @output = ' Source: ' + @source
PRINT @output
SELECT @output = ' Description: ' + @description
PRINT @output
END
ELSE
BEGIN
PRINT ' sp_OAGetErrorInfo failed.'
RETURN
END
end
PRINT 'Send Success!!!'
--destroy object
EXEC @hr = sp_OADestroy @object