0 votes

How do I include the CSS string when using an HTML email?


1 Answer

0 votes
Best answer


Exactly the same way you do in regular html - use <style> tags.

MailBuilder builder = new MailBuilder();
builder.From.Add(new MailBox("alice@mail.com", "Alice"));
builder.To.Add(new MailBox("bob@mail.com", "Bob"));
builder.Subject = "This is HTML test";

builder.Html = @"
      body {background-color:lightgray}
      h1   {color:blue}
      p    {color:green}

  <h1>This is a heading</h1>
  <p>This is a paragraph. <img src = 'cid:image1' /> </p>

// Read attachment from disk...and add it to Visuals collection
MimeData image = builder.AddVisual(@"c:\image.jpg");
image.ContentId = "image1";

IMail email = builder.Create();

using (Smtp smtp = new Smtp())
    smtp.Connect("server.example.com");   // or ConnectSSL for SSL
    smtp.UseBestLogin("user", "password"); 


by (298k points)