Reputation: 172
I am developing a mail landing page. I want to upload html file which I will use as mail body to send email. Currently I am setting mail body like this:
MailMessage mail = new MailMessage();
mail.From = new MailAddress("[email protected]");
mail.To.Add(new MailAddress(MailTo));
mail.Subject = "test";
mail.IsBodyHtml = true;
mail.Body=@"html text with (") replaced with ("") ";
Now my requirement is to input a html file and then use the text as mail body.I want to read the file from the location as the file would be in the same server. So no upload is required. How can I achieve that?
Upvotes: 0
Views: 1146
Reputation: 3239
Using StreamReader
to access the file, read as a stream.
Based on your question, I assume you already have a template.html
file in your root application folder.
Since it's a template, your html should contains some template key text, should add {{title}}, {{Name}}, {{Signature}}
...
For example: template.html
Dear {{Name}},
I would love to discuss with you about {{title}}
Regards,
{{Signature}}
Pseudo code:
string body = string.Empty;
//using streamreader for reading my htmltemplate
using(StreamReader reader = new StreamReader(Server.MapPath("~/template.html")))
{
body = reader.ReadToEnd();
}
//Update your string with template key
body = body.Replace("{{Name}}", name);
body = body.Replace("{{Title}}", title);
body = body.Replace("{{Signature}}", signature);
return body;
Upvotes: 1