bjeverett
asked on
Load HTML File Into Email Message Body
If I have an HTML page located in my ASP.Net app, is there a way to just load the HTML from that file into the body of an email message?
Right now I'm building an HTML string for the message which is a little tedious. :-(
Right now I'm building an HTML string for the message which is a little tedious. :-(
obviously you will hcnage the path to your web application path. not the local harddrive
Andrew
Andrew
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ventaur: Nice Solution :-)
Andrew
Andrew
Thank you!
Anything to help.
-Matt
Anything to help.
-Matt
Automate TextBox Form Mail:
I almost have this figured out, but theres a snag. Unsure how to get TextBox.Text as you'll see below:
[This works]
string emailer = File.ReadAllText(Server.Ma pPath("~/e mailtempl. htm"));
emailer = emailer.Replace("[txtFullN ame]", txtFullName.Text);
emailer = emailer.Replace("[txtEmail Addr]", txtEmailAddr.Text);
System.IO.File.WriteAllTex t(Server.M apPath("~/ emailer.ht m"), emailer);
[This does NOT work]
string emailer = File.ReadAllText(Server.Ma pPath("~/e mailtempl. htm"));
for (int i = 0; i < 10; i++)
{
string txtPattern = Regex.Match(emailer, @"(?<=\[)txt(.*?)(?=\])", RegexOptions.IgnoreCase).T oString(); //ie... matches [txtFullName]
emailer = emailer.Replace("[" + txtPattern + "]", ((TextBox)(FindControl("tx tPattern") )).Text); // error: object not set to the instance...
}
System.IO.File.WriteAllTex t(Server.M apPath("~/ applyEmail er.htm"), emailer);
I almost have this figured out, but theres a snag. Unsure how to get TextBox.Text as you'll see below:
[This works]
string emailer = File.ReadAllText(Server.Ma
emailer = emailer.Replace("[txtFullN
emailer = emailer.Replace("[txtEmail
System.IO.File.WriteAllTex
[This does NOT work]
string emailer = File.ReadAllText(Server.Ma
for (int i = 0; i < 10; i++)
{
string txtPattern = Regex.Match(emailer, @"(?<=\[)txt(.*?)(?=\])", RegexOptions.IgnoreCase).T
emailer = emailer.Replace("[" + txtPattern + "]", ((TextBox)(FindControl("tx
}
System.IO.File.WriteAllTex
Try something like this to suit your needs. By using a MatchEvaluator, you can customize the retrieval of your replacement string in a nice method that uses the matched token value to find your text boxes.
I use this technique to replace tokens with data from the following: IDataReader, DataSet, DataTable, Hashtable, the property on an Object, etc.
I use this technique to replace tokens with data from the following: IDataReader, DataSet, DataTable, Hashtable, the property on an Object, etc.
private string EvaluateMatchForTextBoxInput(Match match) {
string Result = null;
// Find the matched item on the form.
TextBox Input = FindControl(match.Groups[1].Value) as TextBox;
if (Input != null)
Result = Input.Text;
else
Result = "[ missing data ]";
return Result;
}
...
string EmailBody = File.ReadAllText(Server.MapPath("~/emailtempl.htm"));
EmailBody = Regex.Replace(EmailBody, @"\[(\w+)\]", new MatchEvaluator(EvaluateMatchForTextBoxInput), RegexOptions.IgnoreCase | RegexOptions.Multiline);
...
Okay, I'll give it a try. Thank you..
{
string contents = sr1.ReadToEnd();
}
That will get you the contents of the file :-)
Andrew