Skip to content

Instantly share code, notes, and snippets.

@martinnormark
Created January 24, 2012 07:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinnormark/1668751 to your computer and use it in GitHub Desktop.
Save martinnormark/1668751 to your computer and use it in GitHub Desktop.
Read file contents into a string variable
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 = String.Empty;
using (StreamReader sr = new StreamReader(@"C:\Path\To\File.txt"))
{
body = sr.ReadToEnd();
}
MailMessage msg = md.CreateMailMessage("you@anywhere.com", replacements, body, new System.Web.UI.Control());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment