1

I'm trying to return a html string which I'll send email, it works well but I want to add bootstrap style and I cannot do this. How do I to do this ?

Trying

public static String getHtmlMessage(long numero, string descricao, decimal valor){

        string absolute_url = HttpContext.Current.Request.Url.Authority;
        string html = "";
        html += "<html>";
        html += "<head>"; 

        html += "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css \" type=\"text/css\" >";

        html += "</head>";
        html += "<body>";
        html += "<img src=" + "https://" + absolute_url + "/Imagens/logo2.png" + " width=\"250\" />";
        html += "<h3>Message </h3>";
        html += "<ul class=\"list-group\">";
        html +=     "<li class=\"list-group-item\">" + "<strong>Data:</strong> " + DateTime.Now.ToString("dd/MM/yyyy - HH:mm:ss") + "</li>";
        html +=     "<li class=\"list-group-item\">" + "<strong>Nº.Sorte:</strong> " + String.Format("{0:000000}", numero) + "</li>";
        html +=     "<li class=\"list-group-item\">" + "<strong>Descrição:</strong> " + descricao + "</li>";
        html +=     "<li class=\"list-group-item\">" + "<strong>Valor(R$):</strong> " + String.Format("{0:N}", valor) + "</li>";
        html +=     "<li class=\"list-group-item\">" + "<strong>Total(R$):</strong> " + String.Format("{0:N}", valor) + "</li>";
        html += "</ul>";
        html += "<h5>Footer message</h5>";        
        html += "</body></html>";

        return html;
    }

1 Answer 1

1

I've been through this pain before, the short answer is you can't. From an article on css tricks

Things you can't do: ... Link to an external stylesheet. Not many email clients support this, best to just forget it."

Full article: https://css-tricks.com/using-css-in-html-emails-the-real-story/

There's a lot of other styling problems that come up in terms of layout and sizing. It definitely isn't as simple as I figured it should have been

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.