Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everyone,

i am using sql server 2008 r2 express edition for sending email using CDO i have configured everthing such as

"
SQL
exec sp_configure 'show advanced options', 1
exec sp_configure 'Database Mail XPs', 1
exec sp_configure 'Agent XPs',1

"
and after that create a procedure



alter PROCEDURE sp_send_mail_HRrept

@from varchar(500) ,

@to varchar(500) ,

@subject varchar(max),

@body varchar(max) ,

@bodytype varchar(10),

@output_mesg varchar(10) output,

@output_desc varchar(1000) output

AS

DECLARE @imsg int

DECLARE @hr int

DECLARE @source varchar(255)

DECLARE @description varchar(500)

--Create an OLE Instance of CDO

EXEC @hr = sp_oacreate 'cdo.message', @imsg out

--SendUsing

EXEC @hr = sp_oasetproperty @imsg,'configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusing").value','2'

--smtpserver

EXEC @hr = sp_oasetproperty @imsg,'configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserver").value', 'mail.abc.com'

--sendusername

EXEC @hr = sp_oasetproperty @imsg,'configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendusername").value', 'sender@abc.com'

--sendpassword

EXEC @hr = sp_oasetproperty @imsg,'configuration.fields("http://schemas.microsoft.com/cdo/configuration/sendpassword").value', 'XXXXXXX'

--smtpusessl

EXEC @hr = sp_oasetproperty @imsg,'configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl").value', 'False'

--smtpserverport

EXEC @hr = sp_oasetproperty @imsg,'configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport").value', '25'

--smtpauthenticate

EXEC @hr = sp_oasetproperty @imsg,'configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate").value', '1'

--Send Email

--Execute the OLE object to send email

EXEC @hr = sp_oamethod @imsg, 'configuration.fields.update', null

EXEC @hr = sp_oasetproperty @imsg, 'to', @to

EXEC @hr = sp_oasetproperty @imsg, 'from', @from

EXEC @hr = sp_oasetproperty @imsg, 'subject', @subject

EXEC @hr = sp_oasetproperty @imsg, @bodytype, @body

--EXEC @hr = sp_OAMethod @iMsg,'AddAttachment', NULL, 'F:\Mindz Hire.ppsx'
--EXEC @hr = sp_OAMethod @iMsg,'AddAttachment', NULL, 'F:\ppt\corporate_giftts_2.pdf'
--EXEC @hr = sp_OAMethod @iMsg,'AddAttachment', NULL, 'F:\ppt\Mindztechnology.ppt'
--EXEC @hr = sp_OAMethod @iMsg,'AddAttachment', NULL, 'C:\ppt\corporate_giftts_2.pdf'
--EXEC @hr = sp_OAMethod @iMsg,'AddAttachment', NULL, 'F:\mindz\MindZ-Technology.pptx'
--EXEC @hr = sp_OAMethod @iMsg,'AddAttachment', NULL, 'F:\mindz\MProFinders.pptx'

EXEC @hr = sp_oamethod @imsg, 'send', null

--Error Handling `

--Below snippet is checking if the mail is send successfully. If not it captures the Error message and the

--Error Description in the output variables

SET @output_mesg = 'Success'

IF @hr <>0

SELECT @hr
declare @email_id uniqueidentifier
BEGIN

EXEC @hr = sp_oageterrorinfo null, @source out, @description out

IF @hr = 0

BEGIN

set @output_desc = @description

END

ELSE

BEGIN

SET @output_desc = ' sp_oageterrorinfo failed'
select @output_desc as output_desc

END

IF not @output_desc is NULL

SET @output_mesg = 'Error'
select @output_mesg as output_mesg

END

-----------------------------------------------------------------------------------------

but when i run this proc always getting error "-2147220975"
i have done too much googling but do not found any information about this error code

i hope someone help me as soon as possible .
Thanks
Posted
Updated 16-Aug-13 20:09pm
v2
Comments
[no name] 16-Aug-13 10:19am    
http://www.bing.com/search?q=2147220975

1 solution

thanks for reply

but finally i got the solution.
we have a macfee Antivirus installed that was not allowing to mail using sql server 2008,
because there was a bulk emailing not allow, i have just uncheck that option and finally sql emailing was done.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900