I am trying to create a new attachment from a string input and add it to an existing MapiMessage in a PST file.
I do not see any constructors for MapiAttachment class.
Why is it so?
How can I add a new attachment to an existing message accessed as a MapiMessage using pst.ExtractMessage(…)?
// Add plain text attachment
mapiMessage.Attachments.Add("MyAttach.txt", Encoding.UTF8.GetBytes("This is content of palin text attachment"));
// Add attachment from pdf file
mapiMessage.Attachments.Add("document.pdf", File.ReadAllBytes(@"D:\SomePdfFile.pdf"));
Another question, probably a bug,
I’m getting null when I try to access the ItemId of the MapiAttachment.
Sample code:
mapiMessage.Attachments.Add("MyAttach.txt", Encoding.UTF8.GetBytes("This is content of palin text attachment"));
var mapiAttachment = mapiMessage.Attachments.Last<MapiAttachment>();
// Is null
Console.WriteLine(mapiAttachment.ItemId)
Could you please help resolve this?
Thanks,
Srinidhi
Another question, how to add an attachment to an existing message in a pst store.
Given a situation where I have the entry id of a message, I can extract the message using ExtractMessage method on the PersonalStorage object. But this seems to return only a copy of the message but not a reference to the message in the PersonalStorage object.
This way any attachment added through mapiMessage.Attachments.Add(...) do not make any change on the PST file.
How do I add an attachment to an existing message in the PST file?
I see FolderInfo.UpdateMessage(entryIdString, MapiMessage) as an option, but this does not update the attachments list. Looks like only the properties are getting updated, but not the attachment list.
ItemId is used for the attachment identification on the server side. If you’ve created the attachment locally, it doesn’t have ItemId. Can you, please, specify what you wanted to use this property for?
yes, this method is used to update a message properties. Updating attachments is a more complicated process. For updating messages with attachments there’s only one way so far:
I would like to clarify question regarding adding an attachment to an existing message in a pst store.
Is there any updates on EMAILNET-41003? Is it possible to do it without message removing?
Due to the internal structure of PST, adding an attachment to an existing message ultimately involves replacing the original message with a new version that includes the updated content. Even if this isn’t explicitly visible in the API, behind the scenes, the old data is removed and replaced with the modified version. This behavior is inherent to how data is stored and managed within the PST format.
Do you need to implement this as part of a public API?
We’ll attach your request and suggestions to the internal ticket for further consideration. Your input regarding updating attachments through a public API is valuable and will be taken into account during future planning.