Right off the bat, I am not a programmer. It’s weird, but the harder the problem either I can find the answer (Google anyone?) or figure it out (no, really, it’s Google). The easy stuff (I know this because I know)? That I have real trouble with.
I am using MVCMailer + Razor. I got it to send out a mail (dump to c:/), and all was great. I spent some time setting up my mails (I am still toying around with the logic – maybe a future question on a different topic), and I took a break to style it. Several explicative’s (and hours later), I cannot figure this out.
First, I was converting from MVC 2 (used a tool to upgrade, pages worked, etc.). I continued using a Helper class to bring in stylesheets at first in my _Layout.cshtml class:
1) <head> ... <link rel="stylesheet" type="text/css" href="<%= Url.Stylesheet("Default") %>" media="all" />...</head>
When I pull up the *.cshtml generated mail, no styling. NOTE: My Default.css simply imports all my other .css files (I separate out header/content/footer/etc.). However, I tried specifically loading the .css file (Mailer.css – original, I known) that I am using for the mails.
Second, I tried the following from some popular blogs on the subject:
2) <head> ... <link rel="stylesheet" type="text/css" href="@Url.Content("../../Content/Default.css")" /> ... </head>
Yes, I did @using Namespace for that helper. No styling in the actual e-mail.
Finally,
3) I put a <style> block directly in the *.cshtml file.
It worked.
I am stumped. Is it MVCMailer? Am I completely missing something? My goal is to have more than just a text mail, nothing fancy (header/content/footer – some font styling and background color).
This is not an issue with MvcMailer. Its an issue with how email clients treat the CSS files.
Even if your CSS file is rightly linked, most email clients will only use inline CSS. Check this out: http://www.webreference.com/programming/css_html/