Wow...it's been a while since I posted or asked a question.
I writing some html in my script which sends out an email and I wanted to use a style sheet, but for some reason it's not working.
If I take the results of @MyHTML and paste it into notepad, save it as a html file and open it in a browser it works great.
But if I email the results, the table and data shows in my email. But no formatting as if it's completely bypassing the style sheet.
I'm thinking that my email server can't see the server where my CSS is located.
But I wanted to place it out there. And hear what you guys had to say.
If it's not possible to get a style sheet to work. I'll just use the <style> tag and embed my style directly into my proc.
I can't attach any real code because of security. but I'll try my best.
Well Done is better than well said
- Ben Franklin
I writing some html in my script which sends out an email and I wanted to use a style sheet, but for some reason it's not working.
If I take the results of @MyHTML and paste it into notepad, save it as a html file and open it in a browser it works great.
But if I email the results, the table and data shows in my email. But no formatting as if it's completely bypassing the style sheet.
I'm thinking that my email server can't see the server where my CSS is located.
But I wanted to place it out there. And hear what you guys had to say.
If it's not possible to get a style sheet to work. I'll just use the <style> tag and embed my style directly into my proc.
I can't attach any real code because of security. but I'll try my best.
Code:
SET @MyHTML =
N'<link rel="stylesheet" type="text/css" href="\\Server\Share\file.css">'+
N'<caption><font face="verdana" color="Red">TITLE 1</font></caption>'+
N'<table class="clsBasicFmt" >' +
N'<tr><th>Field1</th>
<th>Field2</th>
<th>Field3</th>
<th>Field4</th>
<th>Field5</th>
<th>Field6</th>
<th>Field7</th>
</tr>' +
CAST ( (
SELECT td = CONVERT(VARCHAR(100),[Field1]),'',
td = Field2,'',
td = Field3,'',
td = Field4,'',
td = Field5,'',
td = Field6,'',
td = CONVERT(VARCHAR(30),[Field7],120)
FROM MyDataSource
ORDER BY [Field1]
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
N'</table>' + '<br>'+
N'<caption><font face="verdana" color="Red">TITLE 2</font></caption>' +
N'<table class="clsBasicFmt" >'+
N'<tr><th>Field1</th>
<th>Field2</th>
<th>Field3</th>
<th>Field4</th>
<th>Field5</th>
<th>Field6</th>
<th>Field7</th>
<th>Field8</th>
</tr>' +
CAST ( (
SELECT
td = ISNULL(ROW_NUMBER() over (order by Field1),''),'',
td = ISNULL(CONVERT(VARCHAR(100),[Field2]),'') , '',
td = ISNULL([Field3],'') ,'',
td = ISNULL([Field1],''),'',
td = ISNULL([Field4],'') ,'',
td = ISNULL(CONVERT(VARCHAR(10),[Field5]),'') , '',
td = ISNULL([Field6],'') , '',
td = ISNULL(CONVERT(VARCHAR(30),[Field7],120),'')
FROM MyDataSource2
ORDER BY [Field2]
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
N'</table>'
--SELECT @MyHTML
EXEC msdb.dbo.sp_send_dbmail
@PROFILE_NAME = @Profile,
@Recipients = 'Recipients list',
@body = @MyHTML,
@body_format = 'HTML',
@SUBJECT = @Subject
Well Done is better than well said
- Ben Franklin