Hello,
Before sending the text by email, prepare the text for sending, follow a small 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><pclass="texto">email</p>
<button id="prepareToSend">Prepara html para enviar</button>
As Zull posted, you have the Premailer.net Project: Install via the Package Manager Console:
PM> Install-Package PreMailer.net
See usage on 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 could see in this library, is that it only moves the css to style inline if it is in the same page html:
- Entry:
<!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>
Output 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 quickly:
link