The answer is here : http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/c65502fa-955e-4fa1-b409-238bbb677df7
I think the main thing you're missing is the MIME Content Type on the LinkedResource.
myMagic.css:
body {
background-color: rgb(240,240,240);
font-family: Verdana,Arial,Helvetica,Sans-serif;
font-size: 10pt;
}
h2 {
background-color: rgb(255,255,128);
color: rgb(255,0,0);
}
p {
background-color: rgb(0,0,255);
color: rgb(0,255,0);
font-style: italic;
}
Program.cs:
using System.Net.Mail;
using System.Net.Mime;
namespace MailMessageHTML
{
class Program
{
private static MailMessage ConstructMessage(string from, string to, string subject)
{
const string textPlainContent =@"You need a HTML-capable mail agent to read this message.";
const string textHtmlContent =@"<html><head><link rel='stylesheet' type='text/css' href='cid:myMagicStyle' />
</head>
<body>
<h2>Hello world!</h2>
<p>This is a test HTML e-mail message.</p>
</body>
</html>
";
MailMessage result = new MailMessage(from, to, subject, textPlainContent);
LinkedResource cssResource = new LinkedResource("myMagic.css", "text/css");
//NOTE: Message encoding adds the surrounding <> on this Id cssResource.ContentId =myMagicStyle";
cssResource.TransferEncoding = TransferEncoding.SevenBit;
AlternateView htmlBody = AlternateView.CreateAlternateViewFromString( textHtmlContent , new ContentType("text/html"));
htmlBody.TransferEncoding = TransferEncoding.SevenBit;
htmlBody.LinkedResources.Add(cssResource);
result.AlternateViews.Add(htmlBody);
return result;
}
static void Main(string[] args)
{
MailMessage foo = ConstructMessage(
"sender@foo.com"
,"recipient@bar.com"
, "Test HTML message with style."
);
SmtpClient sender = new SmtpClient();
sender.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
sender.PickupDirectoryLocation = @"...\MailMessageHTML\bin\Debug\";
sender.Send(foo);
}
}
}
NOTE 1: I've specified TransferEncoding.SevenBit on the message parts above. You wouldn't normally do this in a production environment - I've only done it here so you can read the resultant .eml file with Notepad to see what was generated.
NOTE 2: A lot of mail agents won't honour stylesheets linked in message parts. A more-reliable way might be to use inline styles (i.e.: inline ... blocks within the HTML message body).
Good luck,
This answer got from : http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/c65502fa-955e-4fa1-b409-238bbb677df7