0

I want to open (not send) an email with a content in HTML format. I'm using mailto of javascript, and I have created a string that contains the html in c#.net, but the mail shows the tags instead of rendering HTML. I guess I am missing a content-type: text/html but how do I put it? or is there a more correct way to do open email with content ?

Here's the c#.net code that gets the html page

  [HttpPost]
    public ActionResult SetMailContent(int entreatyID)
    {
         Entreaties entreaty = db.Entreaties.Where(e => e.ID == entreatyID).FirstOrDefault();
         if (entreaty == null)
         {
             return new HttpStatusCodeResult(HttpStatusCode.NotFound, "File Not Found");
         }

         StringWriter stringWriter = new StringWriter();
         using (HtmlTextWriter writer = new HtmlTextWriter(stringWriter))
         {
             writer.RenderBeginTag(HtmlTextWriterTag.H1);
             writer.Write(entreaty.OpenDate.ToString("dd/MM/yyyy"));
             writer.RenderEndTag();
         }

         string msg = stringWriter.ToString();
         return Json(new { message = msg});
    }

and javascript code:

window.location = "mailto:mail@gmail.com?body=" + SetMailContent(EntreatyID) + "&subject= " + EntreatyID;

Thank you for your help.

nikib3ro
  • 20,366
  • 24
  • 120
  • 181
Joe
  • 171
  • 2
  • 19
  • 2
    As I could see [here](http://stackoverflow.com/questions/5620324/mailto-with-html-body), this is not possible, because you can't set the e-mail format with this. Is it possible for you to use another way of doing this, other than setting windows.location? Maybe there are another solutions. – Alisson Reinaldo Silva Feb 04 '16 at 15:55
  • Thank you for the reply, so is there another way to open mail with html content not via mailto? – Joe Feb 04 '16 at 16:35

1 Answers1

1

You need to add the HTML content to the DOM, not just display it as a string. You can do this via jQuery for example:

$("#containerId").append($("your mail content"));
DvS
  • 1,025
  • 6
  • 11