|
CREATE PROCEDURE xp_cdosendmail( @Address varchar(255), @Message varchar(8000), @Subject varchar(255), @From varchar(255) = 'defaultemail@domain.com') AS DECLARE @CDO int, @OLEResult int, @Out int --Create CDONTS.NewMail object EXECUTE @OLEResult = sp_OACreate 'CDONTS.NewMail', @CDO OUT IF @OLEResult <> 0 PRINT 'CDONTS.NewMail' --Call Send method of the object execute @OLEResult = sp_OAMethod @CDO, 'Send', Null, @From, @Address, @Subject, @Message, 0 IF @OLEResult <> 0 PRINT 'Send' --Destroy CDO EXECUTE @OLEResult = sp_OADestroy @CDO return @OLEResult See alsofor 'Send email from MS SQL using CDO.' article Send an email from ASP (WSH) using VBSscript, CDONTS and Outlook.Short samples which lets you send an email from ASP or WSH, using several objects (CDONTS.NewMail, CDO.Message, Outlook.Application) and VBScriptCopyright and use this code
The source code on this page and other samples at https://www.motobit.com/tips/
are a free code, you can use it as you want: copy it, modify it, use it in your products, ...
If you use this code, please:
1. Leave the author note in the source.
or
2. Link this sample from you page.
<A Href="https://www.motobit.com/tips/detpg_sqlemailcdo/" Title="This stored procedure lets you send an email using CDO." >Send email from MS SQL using CDO.</A> Do you like it? Rate me on LinkedIn |
© 1996 - 2019 Antonin Foller, Motobit Software | About, Contacts