Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Sending HTML content mails from sqlserver

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-10-26 : 08:01:06
Brijesh writes "Hi,

How can i Send HTML content mails from sqlserver?

Regards,
Brijesh"

iminore
Posting Yak Master

141 Posts

Posted - 2006-10-27 : 08:25:37
This code creates a procedure for sending html emails. You'll need to give 'public' permission to the seevn sp_OA procedures in the 'master' database.

CREATE PROCEDURE dbo.EmailSendHTML
@from varchar(100),
@to varchar(100),
@body varchar(8000),
@subject varchar(200) = null,
@cc varchar(100) = null,
@bcc varchar(100) = null

AS
declare @MailID int, @hresult int

exec @hresult = sp_OACreate 'CDO.Message', @MailID OUT
if @hresult = 0
begin
exec @hresult = sp_OASetProperty @MailID, 'From',@from
exec @hresult = sp_OASetProperty @MailID, 'HTMLBody', @body
exec @hresult = sp_OASetProperty @MailID, 'BCC',@bcc
exec @hresult = sp_OASetProperty @MailID, 'CC', @cc
exec @hresult = sp_OASetProperty @MailID, 'Subject', @subject
exec @hresult = sp_OASetProperty @MailID, 'To', @to
exec @hresult = sp_OAMethod @MailID, 'Send', NULL
exec @hresult = sp_OADestroy @MailID
end

GO
Go to Top of Page
   

- Advertisement -