Tuesday, August 23, 2016

Extract attachments and inline files from a MIME message

  1. MimeMessage msg;
  2. using (var stream = File.OpenRead(fileName))
  3. {
  4. msg = MimeMessage.Load(stream);
  5. }
  6. foreach (var part in msg.BodyParts.OfType().Where(part => !string.IsNullOrEmpty(part.FileName)))
  7. {
  8. using (var stream = File.OpenWrite(Path.Combine(Path.GetDirectoryName(fileName), part.FileName)))
  9. {
  10. part.ContentObject.DecodeTo(stream);
  11. }
  12. }
MimeKit

No comments: