Sicos1977 / MsgKit

A .NET library to make MSG files without the need for Outlook
204 stars 56 forks source link

Can this package be used to convert an .msg file to .eml? #70

Closed MrYossu closed 4 years ago

MrYossu commented 4 years ago

I have a pile of .msg files, and want to be able to open them on a machine that doesn't have Outlook installed. I'd like to convert them to .eml files. Can your package do that?

Thanks

Sicos1977 commented 4 years ago

See the answer in your issue that you opened on MSGReader

MrYossu commented 4 years ago

I asked the question here because I couldn't see how to do it from that answer. You linked to a changeset, but how does that help me read an .msg file and save it as .eml?

Sorry if I missed something, but I couldn't see how to do this from your link.

MrYossu commented 4 years ago

@Sicos1977 OK, I downloaded the source and had a look at the sample project. I see there is a Converter.ConvertMsgToEml method, which looks exactly like what I want, but it just throws a NotImplementedException

So how do I do the conversion?

Sicos1977 commented 4 years ago

You need to download the fork from the other person and compile that one. At the moment I'm not behind my laptop anymore. I can help you but that will be tomorrow.

MrYossu commented 4 years ago

@Sicos1977 I did download his fork, and that's the one that threw the exception. Please see this line of code.

If you get chance to help tomorrow I'd really appreciate it.

Thanks

Sicos1977 commented 4 years ago

I'll look into it tomorrow. I think his code is complete so don't know why you get that exception because that is something that is coming from my repro

MrYossu commented 4 years ago

@Sicos1977 Thanks

Sicos1977 commented 4 years ago

You can get the correct version (with the conversion code) from this link, it seems that he has made a branche that he modified.

https://github.com/BerendHabekotte/MsgKit/tree/US3172_ConvertMsgToEml

Download it as a ZIP, that is what I did and it gave me the code with the MSG to EML conversion

https://github.com/BerendHabekotte/MsgKit/archive/US3172_ConvertMsgToEml.zip

Sicos1977 commented 4 years ago

I'll will see if it is something that I can add the the msgreader. I don't want to mix MsgKit and MsgReader like what he did.

MrYossu commented 4 years ago

@Sicos1977 Thanks for that, but the code doesn't work properly. As an experiment, I added the following line into the sample project in one of the button handlers...

Converter.ConvertMsgToEml(@"D:\msgs\355649890.msg", @"D:\msgs\355649890.eml");

This converted the email itself, but all attachments were empty.

I tried this with a few .msg files, and had the same problem with all of them.

Any ideas? Thanks again.

MrYossu commented 4 years ago

@Sicos1977 Not trying to be rude, but did you get chance to look? As I said, the conversion mostly worked, but all the attachments were blank.

Thanks again for your help

Sicos1977 commented 4 years ago

You mean you did not have any attachments or when you tried to open them there was nothing in it?

MrYossu commented 4 years ago

@Sicos1977 I can't send any example files as they contain confidential information. However, some screenshots might clarify.

If I open one of these converted files (now saved as .eml), I can see that the attachment is recognised (this is in Thunderbird)...

AttachmentInEmail

If I open this, it is blank (this is in the Chromium-based Edge, which is my default PDF viewer)...

AttachmentInPdf

If I open a .jpg attachment, I get this...

AttachmentInJpg

If I try to view an attached text file, I can open it, but it is just blank lines.

If I save these attachments to disk, they look around the right size, but I guess something has gone wrong with the conversion, and the data has been lost.

Any ideas? Thanks again.

MrYossu commented 4 years ago

Sorry, thought I'd replied to this. I wondered why you hadn't answered!

The message had attachments, and these were of the correct size. A text attachment came out as a blank document, an image was unopenable and a pdf file opened, but was just a blank page.

Does that help? Thanks again

MrYossu commented 4 years ago

Oops, seems I did reply! I wonder why my browser didn't show it until just now. Ho hum.

MrYossu commented 4 years ago

@Sicos1977 Any chance you'd be able to look at this? I really need to get these files converted.

Thanks