none
Change color specific words before send RRS feed

  • Question

  • Hi everyone,

    Is possible to get a little bit of help, please. Im trying to send mail from my application, before sending I will like to change all the words "NOTOK" to "NOTOK" forecolor = red. Im coping the values from one DGW to one richtextbox, then the richtextbox is the body from the mail. At the richtextbox is changing the forecolor but is not changing in the email.

    The application is writted in VB.NET

    I have tried this below.

    .body =

    "anytext. "& Environment.NewLine & RichTextBox1.Text

    And this below

    .HTMLBody = "<HTML><BODY><span style=""color:#80BFFF"">Enter</span <b>message</b> <b>'" & RichTextBox1.Text & "'<b>. </BODY></HTML>"

    Im sure someone has the goed idea. Thanks to share your ideas.

    Wednesday, August 30, 2017 10:51 PM

Answers

  • If it is the only formatting, then try the simplest method too:

    .HTMLBody = "<HTML><BODY><span style=""color:#80BFFF"">Enter</span <b>message</b> <b>" & _
                RichTextBox1.Text.Replace("NOTOK", "<span style=""color: red"">NOTOK</span>") & _
                "</b>.</BODY></HTML>"

    It can be improved.


    • Edited by Viorel_MVP Thursday, August 31, 2017 5:26 PM
    • Marked as answer by Lowielou Thursday, August 31, 2017 6:59 PM
    Thursday, August 31, 2017 5:26 PM

All replies

  • Im trying to send mail from my application, before sending I will like to change all the words "NOTOK" to "NOTOK" forecolor = red. Im coping the values from one DGW to one richtextbox, then the richtextbox is the body from the mail.

    There is information available for converting RTF text to HTML.  See, for instance:
    https://www.codeproject.com/Articles/51879/Converting-RTF-to-HTML-in-VB-NET-the-Easy-Way

    That will enable you to include most of the formatting that is available in a Rich Text Box control.

    However, your problem might be that you have not configured the email client to use HTML for the messaging. How you do that depends on how you are sending the email.

    Wednesday, August 30, 2017 11:15 PM
  • Hi Acamar,

    Thank you for your idea and the link, i'm going to take a look into it.

    I was trying to do the HTML i have attached, and is it working, the only thing i cant do is change everytime the word "NOTOK" to "NOTOK" in forecolor red, but is doing the work in the richtextbox.

    Im sure will be a way to find in the body of the email, to search and change the forecolor from a specific word.

    Thanks again for the help

    Thursday, August 31, 2017 4:14 PM
  • If it is the only formatting, then try the simplest method too:

    .HTMLBody = "<HTML><BODY><span style=""color:#80BFFF"">Enter</span <b>message</b> <b>" & _
                RichTextBox1.Text.Replace("NOTOK", "<span style=""color: red"">NOTOK</span>") & _
                "</b>.</BODY></HTML>"

    It can be improved.


    • Edited by Viorel_MVP Thursday, August 31, 2017 5:26 PM
    • Marked as answer by Lowielou Thursday, August 31, 2017 6:59 PM
    Thursday, August 31, 2017 5:26 PM
  • You say you use VB.Net, then we assume one of the latest version. 

    Why do you not use the String interpolation

    It is very simple

    Dim s = $"hello {p.Name} you are {p.Height:0.00}m tall"


    Success
    Cor

    Thursday, August 31, 2017 5:43 PM
  • Hi Viorel,

    Perfect, that is what I was looking for. Thank you very much.

    Kind regards

    Thursday, August 31, 2017 6:59 PM