开发者

Simplify e-mail body in string?

I'm just wondering about this one. I'm creating an ASP.NET webform containing lots of textboxes etc. And I want to send an e-mail based on this stuff. And the e-mails body needs to go i开发者_开发知识库nto a string.

And the string is supposed to contain HTML code, but the syntax changes because of the string. So how can I simplify this? Is there any software or something that lets me do this? Perhaps paste in some HTML code and then convert this to string format, ready to use with vb.net?


If I understand correctly, you are wanting to generate an HTML email from user input via textboxes. If so, you can easily generate HTML using the HtmlTextWriter:

StringBuilder sb = new StringBuilder();
using(HtmlTextWriter writer = new HtmlTextWriter(new StringWriter(sb)))
{
    writer.WriteBeginTag("span");
    writer.WriteAttribute("style", "font-weight:bold;");
    writer.Write(HtmlTextWriter.TagRightChar);
    writer.Write(textboxName.Text);
    writer.WriteEndTag("span");
}
return sb.ToString();

The above will generate a string which looks like:

<span style="font-weight:bold;">user input</span>

The HtmlTextWriter makes it very easy to ensure your markup is semantically correct and valid by mimicking the XML writers.


For converting a HTML formatted string back to plain text try this link,

[http://www.dreamincode.net/code/snippet1578.htm][Strip HTML from string using Regular Expressions]

This will only strip the tags and doesn't remove the html symbols like an ampersand but it will get you started.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜