Search code examples
html-emailcompositionreply

How can an email reply or forward be composed in html emails?


I'm creating a simple email client and I'm having trouble with Reply and Forward in html emails.

When I have the user compose the reply message, how do I append that content to the top of the message? I have done some investigating with how outlook does it by injecting the new message content into a paragraph or div or something like that.

How is it done in general, i.e. gmail, yahoo, etc. How do they figure out where to inject the reply content in the html?

I'm using c# so ideally there is some c# library that can handle this? If not then some idea how it's done generally so I can create a solution for it.

I've read wikipedia's Posting Style article and it gives a good overview of the general idea but nothing about how to do it in html.


Solution

  • Some Background

    When composing HTML email, it is important to recognize that email clients have rather limited support for HTML and the level of support varies across email clients.

    Because of that, although <div> and CSS are the correct layout tools for web pages, that is not true for HTML email. Even today, use <table> for layout control for HTML emails.

    Additionally, the only reliable means to apply CSS is to the HTML elements with a style= attribute on each element. CSS declarations in a <head> section are often ignored by the email client. When crafting HTML email, I actually use CSS in the <head> and, once it looks correct, use this page to convert the HTML to use style= attributes. There are other options.

    Not only will the <head> tag often be ignored, but so will any <body> tag.

    Solving Your Problem

    I would suggest placing the text included in the reply within a table (with a single <tr> and single <td>), and applying an inline CSS style to that table. That allows you to apply formatting, such as placing a colored bar down the left-hand side, italicizing the text, etc.).