Home > Uncategorized > emailing a web page as plain text

emailing a web page as plain text

I was looking for a way to send a web page as an email from a windows form appliction. Quite easily done:

HTMLDocument htmlPage = (HTMLDocument)WebBrowser.Document;

email.BodyFormat = MailFormat.Html;

email.Body = htmlPage.body.innerHTML;

email.From = "me@here.com";

email.To = "you@there.com";

email.Subject = "subject";

SmtpMail.SmtpServer = settings.SMTPServer;



Then, I looked at how to send as plain text, which I used htmlPage.body.innerText, however, this rendered the links unusable, simply saying "Click here" rather than Click here So, I decided to render links as "text" (url). So they could still be used. To do this, I could use extensive parsing and regular expressions, or this nifty piece of code:


foreach(IHTMLElement htmElement in htmlPage.links)


IHTMLAnchorElement htmLink = (IHTMLAnchorElement)htmElement;

htmElement.innerHTML = htmElement.innerText + " (" + htmLink.href + ")";


email.BodyFormat = MailFormat.Text;

email.Body = htmlPage.body.innerText;


Nice eh?


Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: