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
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.