Sicos1977 / MsgKit

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

Sent emails show as draft at recipient #85

Closed trienow closed 2 years ago

trienow commented 3 years ago

Issue

After sending, emails created with MsgKit show a draft icon in Outlook in the inbox of the recipient. Interestingly enough, it doesn't open as a draft, but as a normal email (as one would expect).

grafik

This is the code I used to generate the email:

string filePath = string.Empty;

using (Msg.Email msgMail = new Msg.Email(new Msg.Sender("", ""), "Outlook MSG Test", true, false))
{
    msgMail.Recipients.AddTo("test@domain.de");

    msgMail.BodyHtml = "Test Email Body<br>Dinge<br>Sachen<br><h1>LOUD</h1>";

    filePath = $@"E:\{DateTime.Now.Ticks}.msg";
    msgMail.Save(filePath);
}

return filePath;

Things I've tried

If you have any other Ideas, I'd be glad to hear them. Thanks in advance! Otherwise, the library works great!

trienow commented 3 years ago

Update: I found that setting a specific Icon, that doesn't get displayed (such as MessageIconIndex.UnreadMail) will prevent this from happening.

Since it seems to me like an Outlook issue, I'm closing this issue.

Sicos1977 commented 3 years ago

Nice to see that you got it solved.

Sicos1977 commented 3 years ago

Just curious, for what are you using MSGKit? In what kind of system? I originaly made it because someone wanted to store MSG files in an archive system instead of EML files.

trienow commented 3 years ago

It's interesting that your use-case for MsgKit is almost entirely different from mine.

Basically, the company I work for uses direct SMTP and emails through Outlook. In many cases, direct SMTP email-templates suffice, where we just fill the appropriate placeholders and send it off.

However, in other cases, an email is built by the system with all relevant information such as customer number, name, attachments, etc. and shown in Outlook. This, for example, gives sales people, a chance to add a more personal message / question / greeting if they know the customer well. Outlook Interops have been great for this, until the last couple of years. I had to add a try-catch and then try-again-loop around every Interop command because they will often fail randomly.

Using MsgKit, I create a msg or an oft, if the default signature should be added, and let Outlook open the file by running it. Writing an msg/oft writer had been on my to-do list for quite some time, but I was very reluctant to find your library. Thanks again :)

Sicos1977 commented 3 years ago

Nice that it suited you needs, it was not easy to write a library that can produce MSG files because however the MSG format is well documented it is still very complex. Just set one property wrong and you can't open the file anymore in Outlook. It took me a while to figure out all the properties so that Outlook would be happy and show the MSG files like it was created by Outlook itself.

trienow commented 2 years ago

Sorry to reopen this issue, but my "fix" only works for ofts when setting DraftMode to false.

This got me thinking and digging a bit in this project's source code, until I found this bit here in Email.cs: https://github.com/Sicos1977/MsgKit/blob/3d963e9051f0bbeaf895f9466d3aecfe9d83d6e4/MsgKit/Email.cs#L489-L493

What this seems to do is forcibly overwrite my icon, which I set (or none) and add the draft icon if I activate draft mode. Is this intentional?

Numberg850 commented 2 years ago

Is there a solution or workaround for this please? I'm creating a draft .oft file with an attachment which opens in Outlook ready for the user to add a message and send.

However when sent, the draft icon appears in the sent items and also in the recipient's inbox unfortunately.

Sicos1977 commented 2 years ago

Don't know if it will work (never tried it) but you can override the IconIndex with your own value

image

image

trienow commented 2 years ago

Just a side-note: It works if the Draft-Property is set to false. Otherwise, it doesn't work, as IconIndex gets overridden when saving the email.

I decided to clone the repo (thanks again for providing the source) and just remove Line 492 (see my previous comment). Outlook will add the draft icon automatically, which is why I'm not certain why the line was added in the first place.

Sicos1977 commented 2 years ago

Never thought of that it gets overridden. I will change the code so that it does not override the icon if it is set manually.

Sicos1977 commented 2 years ago

Just released a new nuget package version 2.5.0 with the fix in it.

Numberg850 commented 2 years ago

Excellent, thank you both! In 2.5.0 I was able to manually set the icon to be MessageIconIndex.UnreadMail to stop the draft icon from showing

trienow commented 2 years ago

Thanks Sicos :)