I can't seem to retrieve the AlternateView from System.Net.Mail.AlternateView.
I have an application that is pulling email via POP3. I understand how to create an alternate view for sending, but how does one select the alternate view when looking at the email. I've have the received email as a System.Net.MailMessage object so I can easily pull out the body, encoding, subject line, etc. I can see the AlternateViews, that is, I can see that the count is 2 but want to extract something other than the HTML that is currently returned when I request the body.
Hope this makes some amount of sense and that someone can shed some light on this. In the end, I'm looking to pull the plaintext out, instead of the HTML and would rather not parse it myself.
Mightytighty is leading you down the right path, but you shouldn't presume the type of encoding. This should do the trick:
I was having the same problem, but you just need to read it from the stream. Here's an example:
There is a simpler way:
This works if the first alternative view is the plain text version, as it happens usually.
Its not immediately possible to parse an email with the classes available in the System.Net.Mail namespace; you either need to create your own MIME parser, or use a third party library instead.
This great Codeproject article by Peter Huber SG, entitled 'POP3 Email Client with full MIME Support (.NET 2.0)' will give you an understanding of how MIME processing can be implemented, and the related RFC specification articles.
You can use the Codeproject article as a start for writing your own parser, or appraise a library like SharpMimeTools, which is an open source library for parsing and decoding MIME emails.
http://anmar.eu.org/projects/sharpmimetools/
Hope this helps!