Click here to Skip to main content
15,798,592 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys and Gals ...

I have written an application to send an automated mail when there is a failure in a database.

Everything works well ... however , now I want the font of the body for a specific line to be "Red".

The line is below.

mailResult.AppendLine("Previous Day Management Data Count: " + MgmtTotalDataCount);

Please help me with suggestions. Thanks a MIL
[no name] 20-Jul-12 7:45am    
The HTML color code for red is #FF0000
Richard MacCutchan 20-Jul-12 7:55am    
So if you draw a red bar would it be a foobar?
[no name] 20-Jul-12 8:24am    
Ooooohhhh now that is a question worthy being in QA....

1 solution

Set your content to be HTML:
MailMessage mail = new MailMessage();
mail.Body = body;
mail.IsBodyHtml = true;

Then just specify the colour:
mailResult.AppendLine("<font color=\"red\">Previous Day Management Data Count: " + MgmtTotalDataCount + "</font>");

The result is:
Previous Day Management Data Count: 666

[edit]Forgot to escape the double quotes :doh: - OriginalGriff[/edit]
Share this answer
Rico_ 20-Jul-12 8:06am    
Hi OriginalGriff , thanks for your reply .
I have tried this and cannot use it as the formatting of the mail body goes off.
I had to change it to "msgObj.BodyParts.Add(strResult, BodyPartFormat.Plain);" for the same reason and another service can only consume this mail when it is in plain text.

Is there any other way to change the format colour ?
Rico_ 20-Jul-12 8:23am    
hi , again ...

I have went with the html solution and just outputed another text file for the 3 service. Thanks for your help and input.
Espen Harlinn 20-Jul-12 10:00am    
A beastly good reply :-D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900