Sicos1977 / MsgKit

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

Creating a MSG - how to use AddProperty-method? #114

Closed SigiKoh closed 10 months ago

SigiKoh commented 10 months ago

https://github.com/Sicos1977/MsgKit/issues/78 i am still struggling with the same problem ☹only one hint is too little for a beginner. is it possible, that you tell me the code I need? or any chance of getting a version of MsgKit, which is able to set the „Billing“-Property? i would pay for it?

Sicos1977 commented 10 months ago

I'll try to look into it tomorrow. I'm not home at the moment

Sicos1977 commented 10 months ago

What exactly do you want to do?

SigiKoh commented 10 months ago

hi,

i need to add the property „billinginformation“, but could not manage it with your hint…

using (var email = new Email( new Sender(SenderTextBox.Text, string.Empty), SubjectTextBox.Text, DraftMessageCheckBox.Checked, ReadReceiptCheckBox.Checked)) { email.Recipients.AddTo(ToTextBox.Text); email.Subject = SubjectTextBox.Text; email.BodyText = TextBodyTextBox.Text; email.Attachments.Add("Images\peterpan.jpg");

       email.AddProperty(„BillingInformation“, "1234abcd");

       email.Save("c:\\temp\\email.msg");
                 }

    System.Diagnostics.Process.Start("c:\\temp\\email.msg");

so that my addin can work with this information, when this mail ist sent.

Sicos1977 commented 10 months ago

I added the billing property. Please download the latest version from nuget.

You then can use it like this

image

SigiKoh commented 10 months ago

wow – you made my day! 😊 thank you very much!!

SigiKoh commented 10 months ago

unfortunately it does not work properly yet: After I added the property and saved the msg file, MFCMAPI shows an error.

grafik

When I display this msg-file in outlook, the property disappears: grafik

Sicos1977 commented 10 months ago

I guess it expects some kind of format in that property. Do you have an e-mail that has this property set so that I can look how this property is build up? When looking to the PidLidBilling property (https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/pidlidbilling-canonical-property) it expects an unicode string... but I have no idea what needs to be in this string.

SigiKoh commented 10 months ago

yes, here is a sample …

grafik test.zip

SigiKoh commented 10 months ago

hi, do you think, there is any chance of a solution to my problem? thank you!

Sicos1977 commented 10 months ago

I'll try to look into it again. It was a very busy week last week so I did not do much on my opensource projects.

Sicos1977 commented 10 months ago

I looked into your example e-mail and I think Outlook is probably expecting some other parameters to. But without any good documentation about how this works it is hard to figure out.

Sicos1977 commented 10 months ago

This is all I can find online about that property

https://stackoverflow.com/questions/60117994/vb-net-microsoft-exchange-webservices-data-task-class-find-billinginformati

SigiKoh commented 10 months ago

hi,

for me, whole MAPI is quite complicated.

i asked this question in a forum an got an answer with „NamedProperty“, but this didnt help me …

https://stackoverflow.com/questions/77324103/creating-a-msg-using-msgkit-how-to-use-addproperty-method/77325551#77325551

?

Sicos1977 commented 10 months ago

I just released a new nuget package. This one should work when trying to add a named property. I totally missed it that this was a named property not a normal one so the code I gave you never worked.... sorry about that... I just only now had the time to look into it a little bit deeper.

image

image

SigiKoh commented 10 months ago

Great!! Thank you! :-)

Sicos1977 commented 10 months ago

Just to notice, it is normal that the property gets another value. This is how named properties work.

Just let me know it this fixes your issue so that I can close this issue.

SigiKoh commented 10 months ago

i just tested – works! thumbs up…