90abyss 90abyss - 11 months ago 60
CSS Question

C#: HTML email template font color not working

I'm basically trying to create an HTML email message from my C# code. Everything works as expected but when I use font color, then I receive a blank field in my inbox.

My code snippet:

string type = "<strong><style=\"color: red; \">" + detail.ToString() + "</style>

The type shows correctly when I simply do, type = detail.ToString().
But doesn't work when I add a style. The code simply shows blank word.

Any ideas?

Answer Source

<style> tags are used to define CSS rules. You can't put "content" in them, so this will not work, at all:

   color: red
   <div> Hi mom! </div> <--this line is illegal CSS and will kill the rest of the CSS block </div>

You use style ATTRIBUTES:

<strong><span style="color: red">Hi mom!</span></strong>

or define rules:

   .red { color: red; }

<strong><span class="red">Hi mom!</span></strong>