![]() | Parsing messages |
One of the more common operations that MimeKit is meant for is parsing email messages from arbitrary streams. There are two ways of accomplishing this task.
This topic contains the following sections:
The easiest way is to use one of the Load methods on MimeMessage.
// Load a MimeMessage from a stream var message = MimeMessage.Load (stream);
The second way is to use the MimeParser class. For the most part, using the MimeParser directly is not necessary unless you wish to parse a Unix mbox file stream. However, this is how you would do it:
// Load a MimeMessage from a stream var parser = new MimeParser (stream, MimeFormat.Entity); var message = parser.ParseMessage ();
For Unix mbox file streams, you would use the parser like this:
// Load every message from a Unix mbox var parser = new MimeParser (stream, MimeFormat.Mbox); while (!parser.IsEndOfStream) { var message = parser.ParseMessage (); // do something with the message }