Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Advanced
May 9, 2003

Send Email Using OLE Automation Stored Procedures in SQL Server 2000

Use OLE automation stored procedures to send email:

DECLARE @SenderAddress varchar(100)
DECLARE @RecipientAddress varchar(100)
DECLARE @Subject varchar(200)
DECLARE @Body varchar(8000)
DECLARE @oMail int --Object reference
DECLARE @resultcode int

SET @SenderAddress = 'someone@someisp.com'
SET @RecipientAddress= 'someone@someisp.net'
SELECT @Subject = 'subject of email for today ' + CAST(getdate() AS
varchar(12))
SET  @Body = 'This is the body of my email'

EXEC @resultcode = sp_OACreate 'CDONTS.NewMail', @oMail OUT
IF @resultcode = 0
BEGIN
   EXEC @resultcode = sp_OASetProperty @oMail, 'BodyFormat', 0
   EXEC @resultcode = sp_OASetProperty @oMail, 'MailFormat', 0
   EXEC @resultcode = sp_OASetProperty @oMail, 'Importance', 1
   EXEC @resultcode = sp_OASetProperty @oMail, 'From',
@SenderAddress
   EXEC @resultcode = sp_OASetProperty @oMail, 'To',
@RecipientAddress
   EXEC @resultcode = sp_OASetProperty @oMail, 'Subject',
@Subject
   EXEC @resultcode = sp_OASetProperty @oMail, 'Body', @Body
   EXEC @resultcode = sp_OAMethod @oMail, 'Send', NULL
   EXEC sp_OADestroy @oMail
END
Somaiah Manukonda
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap