Is it possible to use a technique to redirect to a URL from within an application and simply take the page content that would be displayed but instead render it to email or otherwise? I believe I’ve seen the use of InnerHTML but is this really the best way? It seems a bit of a hack, to me.
Thanks!
Is it possible to use a technique to redirect to a URL from within
Share
Yes, this is possible. Download the page using a
WebClientor anHttpWebRequest, put it into theBodyof aMailMessage(also check out theIsBodyHtmlandAlternateViewsproperties), andSendit using anSmtpClient.However, the page at the URL should be created so it has a good chance to be consumed by e-mail clients: very small amount of CSS, table-based layout (argh…), good look even when images are not rendered by the client, left-aligned text, no Javascript, no Flash, no Silverlight, no embedded videos, etc. See this and this for the details of HTML e-mail creation.
If the page you download does not obey these rules, you may have to modify it before sending. The HTML Agility Pack, which was suggested by @Gaby, is an HTML parser, and one of the best tools for this purpose.