SQL ????? ??? SQL ??? ?? ????? ??? ???? ?-??? ????? ?? ??? ????

???? ?????? ???? ??????
???? ID: 312839 - ?? ???????? ?? ?????? ??? ?? ?? ???? ???? ???? ??.
??? ?? ??????? ???? | ??? ?? ??????? ????

?? ????? ??

??????

SQL ??? ????? ?? Microsoft SQL ????? ?? ?-??? ????? ?? ??? ?? ???? ????? ?????? ???? ??? ??????? ?? MAPI ????????? SQL ??? ??, ?????, ?? MAPI ???????? ????? ?? ????? ???? ?????? ??? ?? ????? Windows ??????? ???? ??? ?? Microsoft Windows NT 4.0 ?? MAPI ???????? ??????? ???? ??? ???????, Microsoft Windows 2000 ???? MAPI ???????? ?????? ???? ???? ??? ?????, ??? ?? SQL ??? ?? ????? ???? ????? ???, ?? ?? ???? Microsoft Outlook ???? MAPI ??????? ??????? ???? ?????

SQL ????? ?? ???? ?????? ??? ?????????? ????????? (SMTP) ?-??? ????? ?? ??? ?? ???? ??????? ?? ????? ?? ???? ???? ?????? ?? ???, ??? ?? ????? ???? ???????? ?? ??? NT ????? (CDONTS) ?? ????? ???? ???????? ?? ??? Windows 2000 (CDOSYS) sp_OA SQL Server OLE ???????? ??????? ???????????? ?? ??? ?????? ??? ????? ?? ???? ???? ?? ???? ??? ??? ??????? ??? ????? ?? ?-??? ????? ?? ??? ?? ??????? ?? ????? ???? ???? ?? ?????? ???? ?? ??????? ??????? ?? ???? ??? ????? ?? ?? ???? ????? ??? ?????? ?????? ?????? ?????? ?? ???, ???? ?????? ??? ???????? ?? ?????? ?? ??? ?? ???? ???? ???????? ??? ???? ?? ??????? ?? ?? ?????? ????? ?? ??? ?? ?-??? ?? ??????? ???? ?? ??? ?????? ???? ??????

??? CDOSYS ?????? Windows 2000 ?? ??? ??????? ?? ??? ??, ?? ?? ??????? ???? ??? ?? ?? CDONTS ?? ???? CDOSYS ?? ????? ????? CDONTS ?? ??? Windows Server 2003 ?? ??? ??? ???????? ?????? ??????? ???? ???

??? ?? ???????????? ?????? ??????? ??? Transact SQL CDO ???????? ???? ???? ?? ??? ?? ?? ????? ?? ???? ??? ??????? ?????? ?? ??? ???? ?? ???????????? ??????? ?? ??? ????????? ???, ?? ???? ?? ???? ?? ??? ?? ??????? ???? ??????? ?????? ??? ??? ????? ?? ??? ?????? ???

Microsoft ???????????? ?????? ???? ?????? ?? ??? ?????? ?? ????, ?? ?? ?????? ?? ???? ???? ??? ?? ????? ??, ????? ???? ?? ???, ??????? ?????? ?? ?????? ?? ???? ????? ???????? ?? ??? ????????? ?? ????? ???? ??? ?? ???? ????? ?? ?? ?? ????? ???????????? ???? ?? ??? ?? ???????????? ???? ?? ????? ????? ?? ??????????? ???? ???? ?? ??? ????? ???? ???? ?? ?? ??? ?????? ???? Microsoft ?????????????????? ???????????????????????? ?????? ??????????????? ??????????????????????????? ?????? ???????????????????????????????????? ?????? ?????????????????? ????????? ?????????????????? ?????? ???????????? ?????????, ??????????????? ?????? ?????? ???????????????????????? ?????? ???????????? ????????????????????? ?????????????????????????????? ?????? ???????????? ???????????? ?????? ????????? ???????????????????????????????????? ????????????????????????????????????????????? ??????????????? ?????????????????????????????? ?????????????????? ???????????? ?????? ????????? ????????????????????? ???????????? ?????????????????????

Microsoft Windows NT ????? (CDONTS) ?? ??? CDO ?? ????? ???? ????

CDONTS ????? ??? ?? ???-?????? ??????????? ?? ??? ????? ??????????? ?????? ???? ?? ??? ??????? ???? ??? ?? ?? ?? ?????? ??? ?????????? ????????? (SMTP) ??????? OLE ????? ??? ?? ??????, CDONTS ?????? HTML-?????? ?-??? ?? ?????? ???? ??? Mapi-?????? ???????????, SQL ???, ???? ???? ??? ???????? ??? ??, Microsoft ??????? ????? ????? (IIS) 4.0 ?? ??? ???, CDONTS ??????? ???? ??? ???????? ??? ??, Microsoft ??????? ????? ????? (IIS) 5.0 Microsoft Windows 2000 ??????? ???? ???

CDONTS ?? ???? ??? ???? ??????? ?? ??? Microsoft ?????? ??? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:
177850 CDO 1.2 ?? CDONTS ?? ??? ???? ???? ???
CDONTS ??????? ????? ?????? SMTP ?-??? ????? ??? ???? ???? ??????? ????? ?? ??? SMTP ????? ???? ??, ?? ???? IIS ??????? SMTP ??? ????? ?? ??? ???? SMTP ?-??? ?? ??? ???? ?? ??? ??????? ???? ?? ?? SMTP ??????? ????? ????? ?? ???? ???? SQL ????? ?? ?-??? ????? ?? ??? CDONTS ?? ????? ???? ?? ???, ????? ????? ?? ???? ????:
  1. IIS ??????? ???? ?? ??? ?? isrunning SQL ????? ???????? ?? ?? ??? ???
  2. ???? SMTP ??? ????? ???? "??????? ????? ?? ??? ???" ????????? ???? ????? ?? IIS SMTP ???? ???????? ??? ?? ???? ?? ??? ???? SMTP ??? ????? yourlocal ????? ?? ??? ????? ?? ??? ???? ??? ??? SMTP ?-??? ?? ??? ???? ???
  3. SQL ?? tosend ?-??? ?? ????? ?? ???? ??? ????? ??? ??? ???????? ????????? ??????
?? ?? CDONTS ?? ???? SQL ??? ?? ????? ???? ???, ?? ?? SQL Server ??? ??? ???????? ?? ??????? Microsoft Outlook ???? ??? ??? ??????? ?? ??? ???? ??? ??? ?? ?? Microsoft Exchange ????? ???? ?? ??? ???? ??? ?? ???? "??????? ?????." ?? ??? ??? ?-??? SMTP ?? ?????? ???? ???? ???? ?? ??? ????? ?? ????? ?? ???? ??? ???????, ?? ????? ?? CDONTS ?? ????? ???? SQL ????? ?? ??? ?? ?? ???????? ?? ???? ??? ?-??? ?? ??????? ???? ?? ????? ??? ?? ?? SQL ????? ??? ?? ??????????? ???? ??? ?????

??? ???? ???????? ?? ???? ???? ?? Microsoft Windows 2000 ?? ?????? ???? ???? IIS 4.0 ?? ???????? ?? ??????? ??, ?? ?? Microsoft Windows NT 4.0 ??? ?????? ????????? ?? ???? ???? ???????, ????? ?? ????? ??? ?????

Microsoft Windows NT 4.0 ?? "??????? ?????" ?? ????????? ???? ???? ?? ???? ??? ???? ??????? ?? ??? Microsoft ?????? ??? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:
230235 ???? SMTP ??? ???? ?? ??? IIS SMTP ???? ?? ????????? ???? ????

??????? ????? ????????? ????

  1. ????? ???? ??????? ????, ????? ???? ?? ??? ?????????, ????? ???? ?? ??? ???????????? ?????, ?? ???
    IIS ??????? ?? ????? ?? ??? ??????? ???? ??????? ????? ?????
  2. ???? ????? ?? ??? ???? ?? ?????? ???????? SMTP ??????? ?????, ????-????? ????, ?? ???? ??? ???????? ?????
  3. ????? ??? ?? ?????? ?????, ?? ???? ??? ?????????? ?????
  4. ??????? ????? ??? ???? ? ??? ???? SMTP ??? ????? ?? ??? ???? ????? ??? ?? ???? ??? ?? ???? ???? ???? SMTP ??? servercontact ?? ??? ???? ????? ????
  5. ????????? ???? ?? ?????? ??? ?????????? ????????? (SMTP) ???? ?? ??? ??? SMTP ???? IIS ????? Service.Therefore ?? ?? ??? ??, IIS ????? ???? ?? ????? ?????? ???

CDONTS ?-??? ????? ?? ??? ??? ???????? ????????? ?????

??? ?????? ????????, ?????, ??????, ????? ???, ?-??? ???, ????, ???, ????? ?? ?????? ?? ???? ??? ??? ?? ?? ???????? ???? ???? ?? ???????? ?????, ?????, ??????, ????? ???, ?-??? ???, ????, ???????, ?????, ?? ????? ?? ??? ??? ???????? ?????? ?? ???????? ???? ??????

?? ??? ?? ????? CDONTS ???????? ???? ???? ?? ??? SQL Server OLE ???????? ??????? ???????????? ?? ????? ?? ?-??? ????? ?? ?? ???? ??????? ??? ??? ???????? ????????? ????? ???? ?? ????? ?? ???? ????

CREATE PROCEDURE [dbo].[sp_send_cdontsmail] 
@From varchar(100),
@To varchar(100),
@Subject varchar(100),
@Body varchar(4000),
@CC varchar(100) = null,
@BCC varchar(100) = null
AS
Declare @MailID int
Declare @hr int
EXEC @hr = sp_OACreate 'CDONTS.NewMail', @MailID OUT
EXEC @hr = sp_OASetProperty @MailID, 'From',@From
EXEC @hr = sp_OASetProperty @MailID, 'Body', @Body
EXEC @hr = sp_OASetProperty @MailID, 'BCC',@BCC
EXEC @hr = sp_OASetProperty @MailID, 'CC', @CC
EXEC @hr = sp_OASetProperty @MailID, 'Subject', @Subject
EXEC @hr = sp_OASetProperty @MailID, 'To', @To
EXEC @hr = sp_OAMethod @MailID, 'Send', NULL
EXEC @hr = sp_OADestroy @MailID

???, ???? ?????? ???? ?? ???????? ????????? ?? ????? ???? ?? ??? ?????????? ?????? ????:
exec sp_send_cdontsmail 'someone@example.com','someone2@example.com','Test of CDONTS','It works'
??? ???? ??????? ?? ??? sysadmin ??????? ????? ??? OLE ???????? ??????? ???????????? ??? ???? ???? SQL ????? ?????????? sysadmin ??????? ????? ??? ?? ??? ????? ???? ??, ?? ?? ?-??? ????? ?? ??? ?????? ??? ????? ??? ?? ?? ???????? ????????? ????? ???? ?? ????? ?? ??? ???? ?????? ???, CDONTS ?-??? ????? ?? ??? ??? ??????? ????????? ?????? ???? ?? ??? ??? ???? ??? ?????? ?? ???, ?? ?? Microsoft Visual Basic ????????? ?? ????? ?? ???? ????

CDONTS ??????? SMTP ??????? ????? ?? ??? ?-??? ????? ??? ????? ??? ?-??? ??????? ????? ??? ????? ??? ????????? ???? ??? ?? ?? SMTP ??? ????? ?? ??? ??? ???? ??? SMTP ??? ????? ?-??? ??? ??? ????????? ???? ?? ??? ??? ????? ?? ???? ?? ???: ???? ("someone2@example.com" ?? ?????? ???)? ??? ??? ????????? ???? ???? ?? ?? ??: ????
?-??? ("someone@example.com" ?? ?????? ???) "?? ??????? CDONTS" ???? ?? ????? ?? ?????? ?? ??? ??? "?? ?-??? ?? ????? ??? ?? ??? ??? ????? ???? ??" ????? ???? ??? ??? ?? ?-??? ?? ???? ???? ?? ??????? ?? ?? ???? ??, ????????? ?? ????? ????????? ?????? ?? ??? ???? ?????? ?????

?? HTML-?????? ?-??? ?? ????????? ??? ????? ???? ?? ?????? ??????? ?? ???? ???? CDONTS ?? ???? ??? ????????? ?? ???, ????? Microsoft ??? ???? ?? ????:
http://msdn.microsoft.com/library
???? ??? ???, ???????? ?? ??????? ??????? ????, ????? ???? ?????????? ??????? ????, ?? ???? ??? CDO 1.2.1?? ??????? ?????

?? ????????? ?? ??? SQL Server OLE ???????? ??????? ???????????? SQL Server 2000 ???????? ?????? ??? ???? ???? ????

Microsoft Windows 2000 (CDOSYS) ?? ??? CDO ?? ????? ???? ????

CDOSYS Microsoft Windows 2000 ?? ???????? ????????? ?? ??????? ?? ??? ??? ???????? ???? ?????? ???? ??? ?? ?? ????? ??????????? ?? ?????? CDO ?? ??? Windows NT ????? (CDONTS) ????????? ?? ?????? ???? ??? CDOSYS Windows 2000, ?? ?? ??????? ?? ?????? SMTP ????? ?? ???????? ???

?? CDOSYS ???????? ????????? SMTP ????? ?? ????????? ???? ??? ??? ???? ?? ??? SMTP ????? ?? ????? ???? ?? ??? ????????? ?? ???? ????

CDOSYS ?? ???? ??? ???? ??????? ?? ??? Microsoft ?????? ??? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:
195683 1. x CDO ??????????? ?? CDOSYS ?? ??? ????? ???DLL
CDOSYS ???? ?? ??? ???? ?????? SMTP ????? ?-??? ??? ???? ???, ??????? CDOSYS ?? ???? ??? ??????? ????? ??????? ?? SQL Server ??? ??? ???????? ?? ?? ??? ????? ?? ???????? ???? ??? ?? ?? SMTP ??????? ????? ?? ????????? ???? ?? ??? ???? ??? ??? ???? ?? ??? ???? ??? ?? ??? ???????? ????????? ?? SQL Server ??? ?? ?-??? ????? ?? ??? ????? ?? ???? ??? ?? ????? ?? ????

?? ?? CDOSYS ?? ???? SQL ??? ?? ????? ???? ???, ?? ?? SQL Server ??? ??? ???????? ?? ??????? Microsoft Outlook ???? ??? ??? ??????? ?? ??? ???? ??? ?? ?? ???? Exchange ????? ???? ?? ??? ???? ??? ?? ???? ?????? SMTP ??? ????? ?? ??? ??? SMTP ??? ?? ?????? ???? ???? ???? ?? ??? ????? ?? ????? ?? ???? ???? ???????, ?? ????? ?? ?? CDOSYS ?? ????? ????, ??? SQL ????? ?? ??? ???? ??? ?-??? ?? ??????? ???? ?? ????? ??? ?? ?? SQL ????? ??? ?? ??????????? ???? ??? ?????

CDOSYS ?? ????? SQL Server OLE ??????? ???????? ?? ??? SQL Server OLE CDOSYS ???????? ???? ???? ??? ??????? ?? ?????? ???? ??? ?? SQL Server 2000 ?????? ??? 1 (SP1) ?? SQL Server 2000 ?????? ??? 2 (SP2) ?? ??? ??????? ???? ??? ??? Microsoft CDOSYS ?? ???????? ??????? ???????????? ?? SQL ????? ?? SQL Server 2000 SP1 ???? ?????? ??? ?? ??????? ?? ??? ???? ?? ???? ?? ?????? ???? ???? ???

CDOSYS ??? ????? ???? ?? ??? ??? ???????? ????????? ?????

?? ??? ?? ????? CDOSYS ???????? ???? ???? ?? ??? SQL Server OLE ???????? ??????? ???????????? ?? ????? ?? ?-??? ????? ?? ?? ???? ??????? ??? ??? ???????? ????????? ????? ???? ?? ????? ?? ???? ????

?? ????? ???, ?? ?? ???????? ??? hresult ???????? ???????? sp_OA * ??? ?? ???? ???? ?? ??? ???????? ??? ?????? ?????? ????? ???? ??? hresult (@hr) ????? ??, ?? ????? sp_OA * ??? ????? ??? ???????, ??? ?? hresult ?? ????? ? ?? ??, ?? ????? sp_OA * ??? ??? ?????

???????? ?? ????? ? ?? hresult ?????? ?? ??? ?? ?????? [dbo] ?????? ??? ???????? ???? ???? ???[cdosysmail_failures] ?? ?????? ?? ??? ?? ????? ???? ??? ??, ????? ?????? sp_OAGetErrorInfo ???????? ????????? ????? ?? ?????? ?? ????? ?? ??????? ???? ?? ??? ????? ?????? ?????? ??? ??? ??????? ??????? ???? ?? ??? ?? ?????? ????? ??????? ???? ???? ??? ?? ?? ?????? ?????, ??? ?? ?????? ?? ????? [dbo] ?????? ??? ???????? ??? ?? ????[cdosysmail_failures] ??? ??????? ???? ?? ?? ????? ?? ???? ??? ?? ?? ???? ?? ??? ???????? ?? ????? ?????

??? sp_OAGetErrorInfo ???????? ????????? ????? ???? ???? ??, ?????? ??????? ??????? ???? ?? ??? ????? ?????? ????? ?? ??????? ????:

sp_OAGetErrorInfo ????
-- drop old cdosysmail_failures table if exists
IF (EXISTS (SELECT * FROM dbo.sysobjects WHERE name = N'cdosysmail_failures' AND type='U')) DROP TABLE [dbo].[cdosysmail_failures]
GO
-- Create new cdosysmail_failures table
CREATE TABLE [dbo].[cdosysmail_failures]
		([Date of Failure] datetime, 
		[Spid] int NULL,
		[From] varchar(100) NULL,
		[To] varchar(100) NULL,
		[Subject] varchar(100) NULL,
		[Body] varchar(4000) NULL,
		[iMsg] int NULL,
		[Hr] int NULL,
		[Source of Failure] varchar(255) NULL,
		[Description of Failure] varchar(500) NULL,
		[Output from Failure] varchar(1000) NULL,
		[Comment about Failure] varchar(50) NULL)
GO

IF (EXISTS (SELECT * FROM dbo.sysobjects WHERE name = N'sp_send_cdosysmail' AND type='P')) DROP PROCEDURE [dbo].[sp_send_cdosysmail]
GO

	CREATE PROCEDURE [dbo].[sp_send_cdosysmail] 
	   @From varchar(100) ,
	   @To varchar(100) ,
	   @Subject varchar(100)=" ",
	   @Body varchar(4000) =" "
	/*********************************************************************
	
	This stored procedure takes the parameters and sends an e-mail. 
	All the mail configurations are hard-coded in the stored procedure. 
	Comments are added to the stored procedure where necessary.
	References to the CDOSYS objects are at the following MSDN Web site:
	http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/_cdosys_messaging.asp
	
	***********************************************************************/ 
	   AS
	   Declare @iMsg int
	   Declare @hr int
	   Declare @source varchar(255)
	   Declare @description varchar(500)
	   Declare @output varchar(1000)
	
	--************* Create the CDO.Message Object ************************
	   EXEC @hr = sp_OACreate 'CDO.Message', @iMsg OUT
	   IF @hr <>0 
	     BEGIN
	       SELECT @hr
	       INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'Failed at sp_OACreate')
	       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
                   INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'sp_OAGetErrorInfo for sp_OACreate')
                   RETURN
	         END
	       ELSE
	         BEGIN
	           PRINT '  sp_OAGetErrorInfo failed.'
	           RETURN
	         END
	     END
	
	--***************Configuring the Message Object ******************
	-- This is to configure a remote SMTP server.
	-- http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/_cdosys_schema_configuration_sendusing.asp
	   EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value','2'
	   IF @hr <>0 
	     BEGIN
	       SELECT @hr
	       INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'Failed at sp_OASetProperty sendusing')
	       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
                   INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'sp_OAGetErrorInfo for sp_OASetProperty sendusing')
                   GOTO send_cdosysmail_cleanup
	         END
	       ELSE
	         BEGIN
	           PRINT '  sp_OAGetErrorInfo failed.'
	           GOTO send_cdosysmail_cleanup
	         END
	     END
	-- This is to configure the Server Name or IP address. 
	-- Replace MailServerName by the name or IP of your SMTP Server.
	   EXEC @hr = sp_OASetProperty @iMsg, 'Configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value', cdoSMTPServerName 
	   IF @hr <>0 
	     BEGIN
	       SELECT @hr
	       INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'Failed at sp_OASetProperty smtpserver')
	       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
  	  	   INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'sp_OAGetErrorInfo for sp_OASetProperty smtpserver')
                   GOTO send_cdosysmail_cleanup
	         END
	       ELSE
	         BEGIN
	           PRINT '  sp_OAGetErrorInfo failed.'
	           GOTO send_cdosysmail_cleanup
	         END
	     END
	
	-- Save the configurations to the message object.
	   EXEC @hr = sp_OAMethod @iMsg, 'Configuration.Fields.Update', null
	   IF @hr <>0 
	     BEGIN
	       SELECT @hr
	       INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'Failed at sp_OASetProperty Update')
	       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
  	  	   INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'sp_OAGetErrorInfo for sp_OASetProperty Update')                 
		   GOTO send_cdosysmail_cleanup
	         END
	       ELSE
	         BEGIN
	           PRINT '  sp_OAGetErrorInfo failed.'
	           GOTO send_cdosysmail_cleanup
	         END
	     END
	
	-- Set the e-mail parameters.
	   EXEC @hr = sp_OASetProperty @iMsg, 'To', @To
	   IF @hr <>0 
	     BEGIN
	       SELECT @hr
	       INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'Failed at sp_OASetProperty To')
	       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
  	  	   INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'sp_OAGetErrorInfo for sp_OASetProperty To')                 
                   GOTO send_cdosysmail_cleanup
	         END
	       ELSE
	         BEGIN
	           PRINT '  sp_OAGetErrorInfo failed.'
	           GOTO send_cdosysmail_cleanup
	         END
	     END

	   EXEC @hr = sp_OASetProperty @iMsg, 'From', @From
	   IF @hr <>0 
	     BEGIN
	       SELECT @hr
	       INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'Failed at sp_OASetProperty From')
	       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
  	  	   INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'sp_OAGetErrorInfo for sp_OASetProperty From')                 
                   GOTO send_cdosysmail_cleanup
	         END
	       ELSE
	         BEGIN
	           PRINT '  sp_OAGetErrorInfo failed.'
	           GOTO send_cdosysmail_cleanup
	         END
	     END

	   EXEC @hr = sp_OASetProperty @iMsg, 'Subject', @Subject
	   IF @hr <>0 
	     BEGIN
	       SELECT @hr
	       INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'Failed at sp_OASetProperty Subject')
	       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
  	  	   INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'sp_OAGetErrorInfo for sp_OASetProperty Subject')
                   GOTO send_cdosysmail_cleanup
	         END
	       ELSE
	         BEGIN
	           PRINT '  sp_OAGetErrorInfo failed.'
	           GOTO send_cdosysmail_cleanup
	         END
	     END
	
	-- If you are using HTML e-mail, use 'HTMLBody' instead of 'TextBody'.
	   EXEC @hr = sp_OASetProperty @iMsg, 'TextBody', @Body
	   IF @hr <>0 
	     BEGIN
	       SELECT @hr
	       INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'Failed at sp_OASetProperty TextBody')
	       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
  	  	   INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'sp_OAGetErrorInfo for sp_OASetProperty TextBody')
                   GOTO send_cdosysmail_cleanup
	         END
	       ELSE
	         BEGIN
	           PRINT '  sp_OAGetErrorInfo failed.'
	           GOTO send_cdosysmail_cleanup
	         END
	     END

	   EXEC @hr = sp_OAMethod @iMsg, 'Send', NULL
	   IF @hr <>0 
	     BEGIN
	       SELECT @hr
	       INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'Failed at sp_OAMethod Send')
	       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
  	  	   INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'sp_OAGetErrorInfo for sp_OAMethod Send')
                   GOTO send_cdosysmail_cleanup
	         END
	       ELSE
	         BEGIN
	           PRINT '  sp_OAGetErrorInfo failed.'
	           GOTO send_cdosysmail_cleanup
	         END
	     END
	

	-- Do some error handling after each step if you have to.
	-- Clean up the objects created.
        send_cdosysmail_cleanup:
	If (@iMsg IS NOT NULL) -- if @iMsg is NOT NULL then destroy it
	BEGIN
		EXEC @hr=sp_OADestroy @iMsg
	
		-- handle the failure of the destroy if needed
		IF @hr <>0 
	     	BEGIN
			select @hr
        	        INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'Failed at sp_OADestroy')
	       		EXEC @hr = sp_OAGetErrorInfo NULL, @source OUT, @description OUT
	
			-- if sp_OAGetErrorInfo was successful, print errors
			IF @hr = 0
			BEGIN
				SELECT @output = '  Source: ' + @source
			        PRINT  @output
			        SELECT @output = '  Description: ' + @description
			        PRINT  @output
				INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, 'sp_OAGetErrorInfo for sp_OADestroy')
			END
			
			-- else sp_OAGetErrorInfo failed
			ELSE
			BEGIN
				PRINT '  sp_OAGetErrorInfo failed.'
			        RETURN
			END
		END
	END
	ELSE 
	BEGIN
		PRINT ' sp_OADestroy skipped because @iMsg is NULL.'
		INSERT INTO [dbo].[cdosysmail_failures] VALUES (getdate(), @@spid, @From, @To, @Subject, @Body, @iMsg, @hr, @source, @description, @output, '@iMsg is NULL, sp_OADestroy skipped')
	        RETURN
	END

???, ???? ?????? ???? ?? ???????? ????????? ?? ????? ???? ?? ??? ?????????? ?????? ??????
   declare @Body varchar(4000)
   select @Body = 'This is a Test Message'
   exec sp_send_cdosysmail 'someone@example.com','someone2@example.com','Test of CDOSYS',@Body
??? ???? ??????? ?? ??? sysadmin ??????? ????? ??? OLE ???????? ??????? ???????????? ??? ???? ???? ???? SQL ????? ?????????? sysadmin ??????? ????? ??? ?? ??? ????? ???? ??, ?? ?? ?-??? ????? ?? ??? ?????? ??? ????? ??? ?? ?? ???????? ????????? ????? ???? ?? ????? ??? ???? ?????? ???, ?? CDOSYS ?? ??? ??? ????? ?? ??? ??? ??????? ????????? ?????? ???? ?? ??? ??? ???? ??? ?????? ?? ???, ?? ?? Microsoft Visual Basic ????????? ?? ????? ?? ???? ????

CDOSYS ???? ?? ??? cdoSMTPServerName?? ??? ??? ????????? ???? ???? ?? ?? ?????? SMTP ??? ????? ?-??? ????? ???

SMTP ??? ????? ?-??? ??? ??? ????????? ???? ?? ??? ??? ????? ?? ???? ?? ???: ???? ("someone2@example.com" ?? ?????? ???)? ??? ??? ????????? ???? ???? ?? ?? ??: ???? ?????? ?? ?-??? ("someone@example.com" ?? ?????? ???) ?? ??? ??? ????? ???? ???

??? ?? ?? ?????? ??? ???-?????? ?-??? ?? ???????? ????? ??? ?? ??? ??????? ?? ???? ???? CDOSYS ?? ???? ??? ????????? ?? ???, ????? Microsoft ??? ???? ?? ????:
http://msdn.microsoft.com/library
???? ??? ???, ???????? ?? ??????? ??????? ????, ????? ???? ?????????? ??????? ????, ?? ???? ??? CDO ?? ??? Windows 2000?? ??????? ?????

???? ???????

?? ?????? ?? ?-??? ?????? SMTP ??? ??? ?? ????? ?? ?? ???? ??????? SMTP ????? ??????????? ????? ?? ??? ?? ????? ???? ???? Sp_send_cdosysmail ????? SQL ????? ????????? ??? ???????? ????????? ???? ??, ?? SMTP ????? ??????? ?? ?? ??? ???? ??, ?? ???? ?? ?????? ??????? ????? ??????????? ?? ?????? ?? ?-??? ??? ??? ?? ???? ?? ?? ???????? ????????? ????? ??????????? ?? ??? ?????? ?? ???????? ??? SMTP ????? ??? ?? ???????? ??? ?? ????? ???????

??????? ????? ??????????? ?? ????? ???? ??? ??? ????? ?? ???, ???? ?? ???? ??? ???? ??????? ?? ??? Microsoft ?????? ??? ??? ???? ????? ?? ??? ????? ???? ?????? ?? ????? ????:
286430 ???? HTML ?? ????? ?? ??? ??? CDO ?? ??? Windows 2000 ?? ??????? ????? ??????????? ?? ????? ???? ???????? ???? ???

???

???? ID: 312839 - ????? ???????: 24 ??? 2014 - ??????: 6.0
???? ???? ???? ??:
  • Microsoft SQL Server 2000 Standard Edition
  • Microsoft SQL Server 7.0 Standard Edition
??????: 
kbsqlsetup kbhowtomaster kbmt KB312839 KbMthi
???? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:312839

??????????? ???

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com