December 8, 2008 at 8:32 am
Is it possible to add color when sending email in SQL? Thanks.
December 8, 2008 at 8:44 am
Only if you send HTML mail and put color code in it.
December 8, 2008 at 9:29 am
Here's a base script that you could use.
If you comment out the part that sends email, you could run in query analyzer, paste the text results into an html file and see what it looks like.
set nocount on
declare @start datetime
set @start = getdate()
declare @body1 varchar(8000), @part1 varchar(8000), @part2 varchar(8000),@Count int
declare @results table (resultdata varchar(8000))
Declare @BuSets table
(
setid int,
SomeData varchar(200)
)
set @part1 = '
<TR colspan=2
style="color: #A0522D; font-family: Verdana; font-size: 12;" align=left>'
set @part1 = @part1+ '
'
INSERT INTO @BuSets
--example
select 1, name from master..sysdatabases
select @count =max(setid) from @BuSets
While @count>=0
Begin
select @part1 = @part1 + '
'+ SomeData
+'
'+ case
when SomeData = 'master' then ' '
when SomeData = 'msdb' then ' '
else ' '
end +' '
from @BuSets
where setid=@count
Set @Count=@Count-1
END
print @part1
select @body1 = @part1
--this is the part that actually sends the email
-- usse whatever process you send mail with
--the important part is setting a body type of HTML
--usp_send_cdosysmail is just a nice wrapper around the sp_OA cdo.message object
exec master..usp_send_cdosysmail
@from='yoursender@yourdomain',
@to ='your.recipients@yourdomain',
@subject ='Info',
@body =@body1,
@smtpserver ='yoursmtp server',
@bodytype ='HTMLBody'
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply