exec sp_configure 'show advanced options', 1;
RECONFIGURE;
exec sp_configure 'Ole Automation Procedures', 1;
RECONFIGURE;
declare @text_message nvarchar(180)
,@phone_number nvarchar(15)
,@soap_object int
,@status int
,@output nvarchar(255)
set @text_message = N'Testing Mail'
set @phone_number = N'138000139000'
--Create MSSOAP.SoapClient object
exec @status=sp_OACreate 'MSSOAP.SoapClient', @soap_object out
--SmsManager is Web Service name
exec @status = sp_OAMethod @object, 'mssoapinit', null, 'http://123.456.789.000/SmsManager.asmx?wsdl', 'SmsManager'
--SendTextMessage is webservice method
exec @status = sp_OAMethod @object, 'SendTextMessage', @output OUT, @phone_number, @text_message
if @status <> 0
begin
exec sp_OAGetErrorInfo @soap_object
select @soap_object
end
else
begin
select @output
end
--Destroy MSSOAP.SoapClient object
exec @status = sp_OADestroy @soap_object
GO
|
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 = "[email protected]"
cm.to = "[email protected]"
cm.cc = "[email protected]"
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") = "[email protected]"
.item(ns & "sendpassword") = "*****************"
.item(ns & "smtpconnectiontimeout") = 10
.item(ns & "smtpusessl") = 0
.update
End With
Msgbox('~3~')
cm.send
Set cm = nothing
Msgbox('~success~')
|
use master;
if OBJECT_ID('sp_SendDatabaseMail') is not null
drop proc sp_SendDatabaseMail
go
CREATE PROCEDURE sp_SendDatabaseMail
@recipients varchar(8000), --'[email protected]; [email protected];'
@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 = '[email protected]'
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','[email protected]'
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
|