Hello,
Before sending the text by email, prepare the text for sending, follow a short example with Jquery:
$( "#prepareToSend" ).one( "click", function() {
$("[class=texto]").css( "color", "red" );
});
.texto{
color:green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p class="texto">email</p>
<button id="prepareToSend">Prepara html para enviar</button>
As Zull posted, you have the Premailer.net Project: Install via Nuget (Package Manager Console):
PM> Install-Package PreMailer.net
See use in controller:
public ActionResult TesteEmail()
{
string htmlFile = System.IO.File.ReadAllText(@"C:Emails\teste.html");
var htmlToEmail = PreMailer.Net.PreMailer.MoveCssInline(htmlFile,true);// true para remover a tag style do html dps de copiar os estilos para tags no atributo syle:
return Content(htmlToEmail.Html);
}
From what I can see in this library, it only moves css to style inline if it is in the html page itself:
- Entree:
<!DOCTYPE html>
<html>
<head>
<title>Teste</title>
<style>
.well {background-color: #f5f5f5;}
.text-success {color: green;}
.text-center {text-align: center;}
</style>
</head>
<body>
<div class="well">
<h1 class="text-center text-success">Hello World</h1>
</div>
</body>
</html>
Exit from Content(htmlToEmail.Html);
:
<div class="well" style="background-color: #f5f5f5">
<h1 class="text-center text-success" style="text-align: center;color: green">Hello World</h1>
</div>
I also read this article briefly:
http://chrispebble.com/inlining-a-css-stylesheet-with-c/
Correction. Personal sorry, I did not mention that I use ASP.NET MVC C#. Possibly there must be something on the server side that can do this directly in the View when it is loaded. Only I searched but couldn’t find a practical solution.
– Joandreiy Cordeiro
He did. He’s in tags. http://meta.pt.stackoverflow.com/questions/297/quando-se-deve-colocar-o-nome-da-linguagem-no-t%C3%ADtulo/1911#1911
– Maniero