Reputation: 1646
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!
Upvotes: 1
Views: 279
Reputation: 28678
Yes, this is possible. Download the page using a WebClient
or an HttpWebRequest
, put it into the Body
of a MailMessage
(also check out the IsBodyHtml
and AlternateViews
properties), and Send
it using an SmtpClient
.
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.
Upvotes: 2
Reputation: 19814
Just use WebClient.DownloadFile
method to save the file and then do whatever you wish to do with it.
Upvotes: 0