You must Sign In to post a response.
  • Category: ASP.NET

    Source code for Sending Outlook formatted Email from .Net C#

    I was checking the source code of the article published in Dotnet Spider,, but couldn't find any. Can you please add the same, if it's not already done?

  • #764581
    The code is not attached in given article, To create a formatted email you can use HTML as body
    Use mailDefination class
    see below snippet
    MailDefinition md = new MailDefinition();
    md.From = "";
    md.IsBodyHtml = true;
    md.Subject = "Test of MailDefinition";

    ListDictionary replacements = new ListDictionary();
    replacements.Add("{name}", "Martin");
    replacements.Add("{country}", "Denmark");

    string body = "<div>Hello {name} You're from {country}.</div>";

    MailMessage msg = md.CreateMailMessage("", replacements, body, new System.Web.UI.Control());

    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #764583
    Try this :
    ObjMailMessage.IsBodyHtml = true;//... Must have this
    string szBody="<HTML>\n" +
    "<HEAD>\n" +
    "<TITLE>Sample Email with Formatting</TITLE>\n" +
    "</HEAD>\n" +
    "<BODY><P>\n" +
    "<h1><Font Color=Red>Inline content</Font></h1></P>\n" +
    "</BODY>\n" +
    ObjMailMessage.Body = szBody;
    Hope this will help you.
    Shashikant Gurav

  • Sign In to post your comments