Search code examples
c#.nethtml-emailembedding

Sending HTML in e-mail


I need my .NET desktop app to be able to send various HTML mails, allowing users to create custom templates, including images and possibly CSS style (if they copy/paste the HTML from other sources).

From what I've been reading, it's not that simple:

  • Images need to be embedded and their links replaced with content IDs
  • CSS styles containing images also need to be fixed
  • Background color/image won't work, it's better to wrap the mail in a table and apply the CSS to it
  • SMTP servers can interpret lines starting with a dot as "end of transmission", so at least a space must be added to all such lines
  • Who knows what else

My questions are:

  1. Is there anything else I should take care of?
  2. Is there a library which already does this so that I don't reinvent?

Solution

  • One thing I can think of, make use of Alternate views for those recipients whose mail clients can't/won't accept HTML emails (or they've got it turned off). That way they'll get a plain text version, in which you could include a link to an html version live on the web if they decide want to view it.

    I have also heard that not including a plain text version increases your likelyhood of being marked as spam - this is due to the fact that many mail filters compare the plain text and html versions of a message; if they differ too wildly it's not a good sign for you :-)

    Other spam indicators include html messages which have more pictures than text, and generally sloppy html - broken css, bad links, missing tags etc - consider using some sort of markup validator before sending.