1

I am trying to get the attachment from an .eml file.

The eml file is saved locally in my machine. I need to extract the attachment and attach it to MailMessage.

Able to attach the whole .eml file like below

MailMessage message = new MailMessage();
MemoryStream ms = new MemoryStream(); 
//storing the .eml into this ms 'memory stream'
ms.Position = 0;
message.Attachments.Add(new Attachment(ms, attachmentName));

But, i only need the attachment which is inside this .eml file. How to get that ? (As a memorystream)

---Edit---

Need to load the attachment which is inside the .eml file into the memorystream.

---Edit---

I found this qn somewhat similar. EML Parser

Advanced MIME Parser/Creator/Editor

But, couldn't get the proper solution to my problem. I think below is the issue.

Gets attachment entities. Entity is considered as attachmnet if:

*) Content-Disposition: attachment (RFC 2822 message)

*) Content-Disposition: filename = "" is specified (RFC 2822 message)

*) Content-Type: name = "" is specified (old RFC 822 message)

Jefin Mathew
  • 123
  • 2
  • 7
  • @mjwills thanks for the comment.I need to load the attachment which is inside an .eml file. – Jefin Mathew Jul 20 '18 at 13:18
  • At first glance [LEML](https://github.com/HiraokaHyperTools/LEML) (or [on Nuget](https://www.nuget.org/packages/LEML/)) will do this, although it returns a byte array not a stream. – Rup Jul 20 '18 at 13:37
  • @Rup could you please give a link to an exapmle. So, that it will be easy to understand how to use it. – Jefin Mathew Jul 20 '18 at 14:14
  • 1
    You might want to take a look at [MimeKit](https://github.com/jstedfast/MimeKit). The GitHub page for MimeKit has a number of examples on how to create and parse MIME messages, how to get attachments, etc. The `FAQ.md` has additional examples to answer common questions. If you need more help, send me an email (listed on the GitHub account page) and I'll help you out. – jstedfast Jul 24 '18 at 13:56

0 Answers0