VB Code To Read .eml File And Download Attachments

How to read a physical .eml file (not from Inbox) and download attachments?

Dim stream As ADODB.Stream
Dim email As New CDO.Message
stream = email.GetStream()
stream.Type = ADODB.StreamTypeEnum.adTypeText
stream.LoadFromFile(in_filePath)
stream.Flush()

Dim attachment As CDO.IBodyPart
For Each attachment In email.Attachments
attachment.GetDecodedContentStream().SaveToFile(in_savePath + attachment.FileName, ADODB.SaveOptionsEnum.adSaveCreateOverWrite)

Next


Below arguments are used
Name Type Explanation
in_filePath String Entire file path of .eml file including the file name
in_savePath String Folder path to which the attachments need to be saved. Attachments keep original name when saved


Note: There are 3rd party libraries which can be used to achieve this easily. Since it is not known the authenticity of those classes / libraries, it is recommended to avoid using them.

Hi, I have tried this but giving error mentioned in the image. How we can import ADOBD and CDO? are they imported by default? could you please provide solution?
image

If i use Invoke code, it was giving error as below

@satish.goru, Did you ever find a solution for this? I am trying to find the correct namespace to import and I am having trouble discovering which namespace to use.

Did you find any solution for this?