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, http://www.dotnetspider.com/resources/41465-Send-Formatted-outlook-email-from-NET-C.aspx, but couldn't find any. Can you please add the same, if it's not already done?

    Thanks
    Raja.
  • #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 = "test@domain.com";
    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("you@anywhere.com", replacements, body, new System.Web.UI.Control());

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

  • #764583
    Hi,
    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" +
    "</HTML>";
    ObjMailMessage.Body = szBody;
    Hope this will help you.
    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com


Sign In to post your comments