Reputation: 7347
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>
</strong>";
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?
Upvotes: 0
Views: 988
Reputation: 13378
Edit:
As @Marc B said in his answer. You will need to define it directly by using the style property on the html element or by creating a new class and setting the class property on the html element.
I think you did forgot to set IsBodyHtml
.
Set:
MailMessage.IsBodyHtml = true;
This allows you to use Html in your e-mails.
Reference:
Upvotes: 0
Reputation: 360762
<style>
tags are used to define CSS rules. You can't put "content" in them, so this will not work, at all:
<style>
color: red
<div> Hi mom! </div> <--this line is illegal CSS and will kill the rest of the CSS block </div>
</style>
You use style ATTRIBUTES:
<strong><span style="color: red">Hi mom!</span></strong>
or define rules:
<style>
.red { color: red; }
</style>
<strong><span class="red">Hi mom!</span></strong>
Upvotes: 5