Parsing Outlook Emails (.msg) with Mimekit - outlook

Im attempting to parse .msg files from outlook to get the MIME content in order to save the file as an eml. I'm using Exchange Web Services to save emls as they come through a journaled inbox on the exchange server, but some emails need to be saved after the fact through an outlook add in, though getting them into an eml/MIME format seems more difficult.
The example on the mimekit github page shows it can parse a msg file, though when I attempt it, a System.FormatException is thrown. Does mimekit support msg parsing?
This is what I am doing right now:
var stream = File.OpenRead(#"C:\example.msg");
var parser = new MimeParser(stream);
var msg = parser.ParseMessage();
Any amount of insight would be incredibly helpful.

MSG format is not MIME - try to open it in Notepad. It is an OLE storage file.
To open IStorage file, use StgOpenStorage.
See Difference between a .msg file and a .eml file

Related

How to send an email using VBScript without CDO

I can't send email with VBScript because the Cdo resources have been removed.
For example, this line of code does not work because when I open the link, I see that the resource has been removed:
objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.your.com"
On Microsoft's site it says: "This content is no longer actively maintained."
https://learn.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2003/ms873037(v=exchg.65)
Is there any way to send an email using VBScript where the code doesn't need this kind of reference?

Is there a solution to get a .msg File from the MS Graph API?

I have the task to get several Mails with the Graph API and archive those as .msg files to a server.
Right now, i'm only able to get mails as MIME. Is there a way to transform those into .msg files?
MSG file format is specific to the Windows version of Outlook. Neither Graph nor EWS expose that file format in any way. You can create an MSG file (see How to create ".msg" file without using outlook in mfc?) and import EML into it.
Also note that Outlook will be just as happy to open and display an EML file as an MSG file, so it might make sense to work with EML files, even if they don't expose all the information and MAPI specific properties that an MSG file can store.

How to access to Outlook (desktop client on macOS) stored emails programmatically

I'm trying to read emails from Outlook (desktop client on macOS) installation programmatically.
For Thunderbird I only need to read the files stored in /Users/xxxx/Library/Thunderbird/Profiles/xxxx.default-release/ImapMail/someemailaccount/.
Each file on that directory is named after the name of each folder on the email account (INBOX, Sent, etc.) and it contains all the emails (header, body and attachments). So all I have to do is to read that file with some programming language and apply the right decoder depending on the Content-Transfer-Encoding header.
For Outlook I found this file: /Users/xxxx/Library/Group Containers/UBF8T346G9.Office/Outlook/Outlook 15 Profiles/Main Profile/HxStore.hxd but it looks doesn't look to be readable, is it on a binary format? it is compressed or encrypted?
I tried to see its contents using Hex Field app and it displays that the file contains some blocks of data but those blocks look to be broken or encrypted/compressed (more info about that file here https://boncaldoforensics.wordpress.com/2018/12/09/microsoft-hxstore-hxd-email-research/):
<html><head>
<meta http-equiv="Content-Type" cp="text/;ñ; charset=utf-8"></Lð<body><div dir="ltr">1234567890ñ>
...
As you can see above, the contents look to be there but there are some strange characters on it. Also, the file has a lot of sections with no characters or random ones.
Does anybody know how can I read this file?
If you use the older outlook interface (or switch back to it) you can access the underlying sqlite database pretty easily.
However this will be discontinued at some point and Outlook will completely switch to the new interface based on Core Spotlight.
I am also looking for a way to access emails from the new interface, and yes the data seems to be in this file. Anybody else have pointers on how to access?

Which OlSaveAsType can I add to the MailItem SaveAs method?

I am getting the currently selected mailItem from the explorer and saving it to the local file system. The file is then being uploaded to a server. My problem is sometimes the server (which I have no control over) returns that the file format is invalid.
I save the mailItem with the following code:
oMailItem.SaveAs("C:\path\savedEmail.msg")
This creates a file which is 174kb in size. If I add the OlSaveAsType of olMSG then I get the same file size.
If I save the exact same email with the Outlook UI then the chosen/suggested Message format is Unicode. This produces a file of about 251kb ie. much bigger. If I save it with the above code and olMSGUnicode then I also get the same file size.
I am therefore assuming that leaving out the OlSaveAsType option saves the mailItem as an olMSG.
I am currently also assuming that this may be causing some issues with the upload to the server.
What property of a mailItem tells me which OlSaveAsType to use? Can I safely use olMSGUnicode for all saves?
Yes, you can safely use olMSGUnicode format on all modern versions of Outlook.
But the real problem is why the server (?!) returns an error that the format is invalid? Was it corrupted? Can you successfully open the same file you sent to the server? You need to figure out why that error is returned.

RDOMail.SaveAs sometimes doesn't work over a UNC

I have a C# Outlook add-in that is using the Redemption library.
This add-in, among other things, copy the selected mail to a share somewhere on the network.
It usually works pretty well but sometimes, the .msg file on the share seems to be corrupted. It cannot be read by the service that tries to process it. Double clicking on it shows this message: "Cannot read the item".
Sometimes, I can see an error message:
SaveEmail - System.Runtime.InteropServices.COMException (0x8007000):
Error in StgCreateDocFile: 0x8007000 at
Redemption.IRDOMail.SaveAs(String Path, Object Type) at
XYZNameSpace.Email.SaveEmail(...)
Here the code that save the mail to the share:
// Save the mail in a temp local file first
mailItem.SaveAs(temppath, Outlook.OlSaveAsType.olMSG);
(... some processing ...)
// Reload the mail
RDOMail rm = rdoSession.GetMessageFromMsgFile(temppath);
// Save it again on a share
rm.SaveAs(filePathName, Outlook.OlSaveAsType.olMSG);
Note 1 : I don't know why the mail is first saved locally!
Note 2 : It is using an older version of Redemption (2015).
Note 3 : The size of the message doesn't seem important. However, they are
usually between 2 and 15 MB.
Many thanks in advance.
IStorage API does not really like remote drives - there is no way for the storage sharing features to work.
Opening and saving the message the second time really does not make much sense - why not simply copy the MSG file using the file system API?

Resources