mihaildamjan
Programmer
Hello all,
Got this code that is supposed to send an email directly from the stored procedure.
It would be really neat to be able to do that ,but allthough it doesn't error out, it does not send the email at all.
My understanding is that if you have the Outlook set up on the PC that you are running the procedure from, you also have cdonts.dll required for the procedure to work.
Please run the code below and if you get it to work , please let me know how you did it.
***************************
DECLARE @result INT
DECLARE @object INT
DECLARE @propertyvalue VARCHAR(255)
PRINT 'Creating the CDONTS.NewMail object'
EXEC @result = sp_OACreate 'CDONTS.NewMail', @object OUTPUT
IF @result <> 0
PRINT 'sp_OACreate Failed'
ELSE BEGIN
PRINT 'Get the From property'
EXEC @result = sp_OAGetProperty @object, 'Version', @propertyvalue OUTPUT
IF @result <> 0
PRINT 'sp_OAGetProperty Failed'
ELSE BEGIN
PRINT 'CDONTS Version = ' + @propertyvalue
PRINT 'Set the From property'
EXEC @result = sp_OASetProperty @object, 'From', 'mihail.damjan@SomeEmailAddress.com'
IF @result <> 0
PRINT 'sp_OASetProperty Failed'
ELSE BEGIN
PRINT 'Sending the message using the Send method'
EXEC @result = sp_OAMethod @object, 'Send', NULL, 'mihail.damjan@SomeEmailAddress.com', 'mihail.damjan@SomeEmailAddress.com',
'My test message', 'Hello world! Look at my body!'
IF @result <> 0
PRINT 'sp_OAMethod Failed'
ELSE BEGIN
PRINT 'Destroying the CDONTS.NewMail object'
EXEC @result = sp_OADestroy @object
IF @result <> 0
PRINT 'sp_OADestroy Failed'
END
END
END
END
*******************************************
and here is the result of running the procedure
Creating the CDONTS.NewMail object
Get the From property
CDONTS Version = 1.2
Set the From property
Sending the message using the Send method
Destroying the CDONTS.NewMail object
***************************
Got this code that is supposed to send an email directly from the stored procedure.
It would be really neat to be able to do that ,but allthough it doesn't error out, it does not send the email at all.
My understanding is that if you have the Outlook set up on the PC that you are running the procedure from, you also have cdonts.dll required for the procedure to work.
Please run the code below and if you get it to work , please let me know how you did it.
***************************
DECLARE @result INT
DECLARE @object INT
DECLARE @propertyvalue VARCHAR(255)
PRINT 'Creating the CDONTS.NewMail object'
EXEC @result = sp_OACreate 'CDONTS.NewMail', @object OUTPUT
IF @result <> 0
PRINT 'sp_OACreate Failed'
ELSE BEGIN
PRINT 'Get the From property'
EXEC @result = sp_OAGetProperty @object, 'Version', @propertyvalue OUTPUT
IF @result <> 0
PRINT 'sp_OAGetProperty Failed'
ELSE BEGIN
PRINT 'CDONTS Version = ' + @propertyvalue
PRINT 'Set the From property'
EXEC @result = sp_OASetProperty @object, 'From', 'mihail.damjan@SomeEmailAddress.com'
IF @result <> 0
PRINT 'sp_OASetProperty Failed'
ELSE BEGIN
PRINT 'Sending the message using the Send method'
EXEC @result = sp_OAMethod @object, 'Send', NULL, 'mihail.damjan@SomeEmailAddress.com', 'mihail.damjan@SomeEmailAddress.com',
'My test message', 'Hello world! Look at my body!'
IF @result <> 0
PRINT 'sp_OAMethod Failed'
ELSE BEGIN
PRINT 'Destroying the CDONTS.NewMail object'
EXEC @result = sp_OADestroy @object
IF @result <> 0
PRINT 'sp_OADestroy Failed'
END
END
END
END
*******************************************
and here is the result of running the procedure
Creating the CDONTS.NewMail object
Get the From property
CDONTS Version = 1.2
Set the From property
Sending the message using the Send method
Destroying the CDONTS.NewMail object
***************************