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: